[R] functions different in R and S

David Brahm brahm at alum.mit.edu
Wed Feb 19 17:00:09 CET 2003

Helen Yang <Huiqin.Yang at noaa.gov> wrote:
> I wonder whether there is any resource that can point to useful substitutes
> for S functions that are not recognized by R.  At the same time whether there
> is a list of functions, which appear in both R and S but which don't do
> exactly the same thing.

As Prof. Brian D. Ripley <ripley at stats.ox.ac.uk> said, see the FAQ at:
  <http://www.r-project.org/> (Click "FAQs", "R FAQ", "R and S".)

Here are my own crib notes on some differences that I care about.  Note "S"
here really means S-Plus version 6.1.2.  I have not checked whether any of
these have changed since October.  This list is certainly not complete.

                     ***   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.

                              -- David Brahm (brahm at alum.mit.edu)

More information about the R-help mailing list