Thursday, August 8, 2013

R package writing tips

S4 union classes
To create a class that accepts different class objects:

setClassUnion("AorB", c("classA", "classB")) 

Saving data files in R packages
They need to be compressed to avoid warnings when running R CMD check

save(a,b,c,file="savefile.rda",compress='xz') 

Make R package zip (for Windows) on Linux 
make destination folder eg. testand write to test

mkdir test 
R CMD INSTALL -l test pkgname 
cd test 
zip -r pkgname pkgname


R package documentation writing
If you are generating Sweave files from Lyx (Rnw), add

%\VignetteIndexEntry{Your-Title}

to the top of your Rnw file