R: Handy extensions

Some functions collated here are from other sources on the web. The sources are given inside the source code (q.v.).

Example .rprofile

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


# you can then use it with:
writeForeignMySPSS(dataframe, datafile, codefile[, varnames] )

Type III sums of squares with ezANOVA v2.1-0

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.


# you can then use it with:
        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")

Half borders (left/bottom axes only) in ggplot2

This hack to ggplot2 allows left/bottom ("L") borders only, and some other possibilities. See Graphs 2 for usage, but examples include:

Install it with:

Valid HTML 4.01 Transitional
Valid CSS