[R] R - S compatibility table
David Brahm
brahm at alum.mit.edu
Tue Oct 21 22:49:17 CEST 2003
Purvis Bedenbaugh <purvis at mbi.ufl.edu> wrote:
> I started looking for an R-S compatibility table but didn't find it.
> Examples:
> 'stdev' is now 'sd' - is it exactly the same computation ?
> couldn't find a built-in for error.bar()
> syntax that is an error in R: param(thisframe,"b") <- value
It's a moving target! I wrote such a list in October 2001, and revised it a
year later, but I haven't updated it since then (I no longer use S-Plus). Some
people (e.g. Paul Gilbert) replied that they also had lists which didn't
overlap much with mine, suggesting we were each seeing just a small part of the
puzzle. So maintaining a complete and current list would be quite a challenge.
Paul also mentioned to me a mailing list "R-sig-S" on the topic:
<https://www.stat.math.ethz.ch/mailman/listinfo/r-sig-s>
but it seems dead since May 2001.
That said, here's my year-old list. Note "S" means "S-Plus 6.1.2" (not "The S
Language") and "R" probably means "R-1.6.0".
*** R vs. S (DB 10/28/02) ***
Language differences:
- Scoping rules differ. In R, functions see the functions they're in. Try:
f1 <- function() {x <- 1; f2 <- function() print(x); f2()}; f1()
- Data must be loaded explicitly in R, can be attach()'ed in S.
Addressed by my contributed package "g.data".
- R has a character-type NA, so LETTERS[c(NA,2)] = c(NA,"B") not c("","B")
- paste("a","b", sep="|", sep=".") is an error in R; ok in S.
- for() loops more efficient in R.
Graphics differences:
- Log scale indicated in S with par(xaxt)=="l", in R with par("xlog")==T.
- R has cex.main, col.lab, font.axis, etc. Thus title("Hi", cex=4) fails.
- R has plotmath and Hershey vector fonts.
- R has palette(rainbow(10)) to define colors (both screen and printer).
Functions missing from R:
- unpaste, slice.index, colVars
Functions missing from S:
- strsplit, sub, gsub, chartr, formatC
Functions that work differently:
- system() has no "input" argument in R.
- substring(s,"x") <- "X" only works in S, but R has s <- gsub("x","X",s).
- scan expects numbers by default in R.
- which(<numeric>) converts to logical in S, is an error in R.
- The NULL returned by if(F){...} is invisible in R, visible in S.
- The NULL returned by return() is visible in R, invisible in S.
- Args to "var" differ, and R has "cov". S na.method="a" ~ R use="p".
- var (or cov) drops dimensions in S, not R.
- cut allows labels=F in R, not in S (also left.include=T becomes right=F).
- Last argument of a replacement function must be named "value" in R.
- tapply(1:3, c("a","b","a"), sum) is a 1D-array in R, a vector in S.
- probability distribution fcn's have arg "log.x" in R (ref: Spencer Graves)
--
-- David Brahm (brahm at alum.mit.edu)
More information about the R-help
mailing list