code mnemonics

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


Stag all removed files in git

git rm $(git ls-files –deleted)


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')

        

 


Insert or overwriting mode shortcut

Not really a command, but super annoying for a linux computer using a mac keyboard.

Shortcut: fn + return

Leave a comment