[R] Several R vs S-Plus issues
David Brahm
a215020 at agate.fmr.com
Wed Oct 3 17:35:58 CEST 2001
Hi, all,
I've been converting code from S-Plus ("S" for short) to R for a few weeks.
Here are some differences I've found, aside from the big well-known ones
(scoping, models, data storage) and the contents of Kurt Hornik's FAQ section
3.3.3. Let me start with the ones that seem like serious bugs or deficiencies:
1) LETTERS[c(NA,2)] in S is c("","B"), but in R is c("NA","B").
This is TERRIBLE! I have a ton of S-Plus code that looks like:
y$ticker <- z$ticker[match(y$cusip, z$cusip)]
and I count on a ticker of "" to indicate failed lookups. Not only will
I need to change all that code, but I'll never be able to trade Nabisco
(ticker NA) again. PLEASE re-consider this choice, or at least make it
an option: option(na.char="").
2) system() has no "input" argument in R.
Here's a (Unix) example:
S> system("cd mydir; latex myfile", input="x")
which goes to the directory where myfile lives and LaTeX's it, passing
an "x" through STDIN in case LaTeX encounters an error. My R fix is:
R> system("cd mydir; echo x | latex myfile")
Note that it's not as simple as cmd <- paste("echo",input,"|",cmd).
3) R> myfun <- function(x, ...) {x[...] <- 0; x}
R> myfun(3)
Error in myfun(3) : SubAssignArgs: invalid number of arguments
It failed because no ... was given. Fortunately, this is easily patched:
R> myfun <- function(x, ...) {if (missing(...)) x[]<-0 else x[...]<-0; x}
4) Missing functions:
a) identical() [scheduled for 1.4.0]
b) slice.index()
c) rowSums(), colSums(), colVars(), etc.
d) unpaste() - R has strsplit, whose result is like the transpose of unpaste
5) rowsum() gives character dimnames in S, factor numbers in R.
I've reported this early, and Brian D. Ripley promised a fix in 1.4.0.
OK, the rest are just differences, not complaints. In fact, sometimes they are
very good differences.
1) Same argument given twice produces an error in R; S takes the last one.
S> mean(x=4, x=5) # Returns 5
R> mean(x=4, x=5) # Error
2) row.names(y) <- LETTERS[1:3] coerces list to dataframe in S, is error in R.
3) Default "what" for scan in S is "", in R is double(0).
4) Default "quote" for scan is "'\"" in R, causes different behavior than S.
5) which(<numeric>) converts to logical in S, is an error in R.
6) The NULL returned by if(F){...} is invisible in R, visible in S.
7) The NULL returned by return() is visible in R, invisible in S.
8) Args to "var" differ, and R has "cov". S na.method="a" is like R use="p".
9) var (or cov) drops dimensions in S, not R.
10) cut allows labels=F in R, not in S (also left.include=T becomes right=F).
11) substring(s,"x") <- "X" only works in S, but R has s <- gsub("x","X",s).
12) S function casefold() replaced in R by toupper() or tolower().
13) Functions missing from S: sub(), gsub(), chartr(), toupper(), tolower()
14) Log scale indicated in S with par(xaxt)=="l", in R with par("xlog")==T.
-- David Brahm (a215020 at agate.fmr.com)
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list