code mnemonics

Compilation of useful programming tips that I sometimes need but always forget about.


Roxygen skeleton

To add the roxygen2 skeleton to document a function:

shift+ctrl+alt+r

shift+opt+cmd+r

source


Correspondance between reshape2::melt and tidyr::gather, reshape::dcast and tidyr::spread

library(reshape2)
library(tidyr)
library(dplyr)

mini_iris <- iris[c(1, 51, 101), ]

# melt
melted1 <- mini_iris %>% melt(id.vars = "Species",value.name = 'dimension',variable.name='trait')
melted2 <- mini_iris %>% gather(key='trait', value='dimension', -Species)

# cast
melted1 %>% dcast(Species ~ trait, value.var = "dimension")
melted2 %>% spread(key='trait', value='dimension')

        

 


TO COME…

TryCatch structure

Advertisements

About moisesexpositoalonso

I am an enthusiastic young researcher. Born in 1990 and raised in Alicante, a coastal town in south-east Spain. With background in experimental ecology as an undergraduate (Sep2008-Jul2013) and population & quantitative genetics as masters student (Sep2013-Sep2014). Recently I started my PhD project (Oct2014-Sep2018) that deals with measuring evolutionary rates employing 1001 genomes of Arabidopsis and, particularly, understand climatic adaptation.
This entry was posted in Sin categoría. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s