[R] Several R vs S-Plus issues

Monder, Harvey Harvey.Monder at pharma.com
Wed Oct 3 20:29:03 CEST 2001

Also in assign() there some arguments lacking in R such as 'frame' and
'where', though I guess that 'frame' in S may be similar to 'pos' in R.


	-----Original Message-----
	From:	David Brahm [SMTP:a215020 at agate.fmr.com]
	Sent:	Wednesday, October 03, 2001 11:36 AM
	To:	r-help at stat.math.ethz.ch
	Cc:	Kurt.Hornik at ci.tuwien.ac.at; r-bugs at r-project.org
	Subject:	[R] Several R vs S-Plus issues

	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
	(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

	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
	  (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,
	     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 <-

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

	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

	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

	11) substring(s,"x") <- "X" only works in S, but R has s <-

	12) S function casefold() replaced in R by toupper() or tolower().

	13) Functions missing from S: sub(), gsub(), chartr(), toupper(),

	14) Log scale indicated in S with par(xaxt)=="l", in R with

				-- David Brahm (a215020 at agate.fmr.com)
	r-help mailing list -- Read
	Send "info", "help", or "[un]subscribe"
	(in the "body", not the subject !)  To:
r-help-request at stat.math.ethz.ch
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