R: Handy extensions
Back to Local tips for R
Some functions collated here are from other sources on the web. The sources are given inside the source code (q.v.).
An example .Rprofile (save as ".Rprofile" in your home directory). It doesn't do much except auto-set R's column width to the size of your display window. To execute its contents from the web (which is not the same as having it as your .Rprofile), copy this code fragment and paste it into R:
From https://stat.ethz.ch/pipermail/r-devel/2008-October/050918.html: a writeForeignMySPSS function to write SPSS format (one datafile, one .SPS syntax file to read it and to set up variable types - the syntax file created knows the name of the datafile, so just execute the syntax file from within SPSS):
source("http://egret.psychol.cam.ac.uk/statistics/R/extensions/writeForeignMySPSS.R") # you can then use it with: writeForeignMySPSS(dataframe, datafile, codefile[, varnames] )
A hack to ezANOVA version 2.1-0 (based on package ez by Mike Lawrence) to allow Type III sums of squares as an option (see ANOVA as to why this might be desirable, and see this discussion on Statistical Analysis about it).
Note that from ez version 3, there is a
type= option (use as e.g. “type=3”), making this extension redundant.
source("http://egret.psychol.cam.ac.uk/statistics/R/extensions/hack_ezANOVA.R") # you can then use it with: ezANOVA(dataframe, dv=.(depvar(s)), wid=.(subjectidentifier), within=.(withinsubjectvariable(s)), between=.(betweensubjectvariable(s)), otheroptions, detailed=TRUE, type=c("II", "III", 2, 3) ) # example for a two-factor between-subjects design, where data2 is a data frame containing columns depvar (dependent variable), A (factor), B (factor), S (subject label): ezANOVA(data2, dv=.(depvar), wid=.(S), between=.(A,B), detailed=TRUE, type="III")
This hack to ggplot2 allows left/bottom ("L") borders only, and some other possibilities. See Graphs 2 for usage, but examples include:
opts( panel.border = theme_border(c("bottom", "left")) )
opts( panel.border = theme_border(c("b", "l", "r")) )
opts( panel.border = theme_border_numerictype(9) )
opts( panel.border = theme_L_border() )
Install it with: