[Rd] two minor differences in behavior of R and S-plus

Tony Plate tplate@blackmesacapital.com
Thu, 14 Mar 2002 21:59:03 -0700


I found two minor differences when porting some S-plus code to R (the code 
was written for Splus 3.5 Unix).

(1) The function c(), when applied to a name and a character, under S-plus 
coerces the name to character data and returns a vector of character data, 
but in R returns a list containing both objects intact

(2) The call match.call(expand.dots=F) returns an object that behaves 
differently: under S-plus it is a call object with a "list" functor, under 
R it is an ordinary list with no "list" functor.  (e.g., 
as.character(match.call(expand.dots=F)$...) under S-plus has 
length(list(...))+1 elements, of which the first is "list", but under R it 
has just length(list(...)) elements)

Example of (1)

under R (both 1.5 and 1.4.1):

 > c("foo", as.name("bar"))
[[1]]
[1] "foo"

[[2]]
bar

under S-plus 6.0 (and earlier, I believe)

 > c("foo", as.name("bar"))
[1] "foo" "bar"

[I would agree that it is unclear what the most desirable behavior is, and 
would also agree that clean code would do an as.character() on a name 
before attempting to concatenate it with character data - I changed my code 
to do this.]

Example of (2)

Under R 1.4.1:
 > (function(...)browser())(x=1,y=2)
Called from: (function(...) browser())(x = 1, y = 2)
Browse[1]> match.call(expand.dots=F)
(function(...) browser())(... = list(x = 1, y = 2))
Browse[1]> match.call(expand.dots=F)$...
$x
[1] 1

$y
[1] 2

Browse[1]> is.call(match.call(expand.dots=F)$...)
[1] FALSE
Browse[1]> names(match.call(expand.dots=F)$...)
[1] "x" "y"
Browse[1]> as.character(match.call(expand.dots=F)$...)
[1] "1" "2"


Under S-plus 6.0:
 > (function(...)browser())(x=1,y=2)
Called from: (function(...)  browser())....
b()> match.call(expand.dots=F)
(function(...)
browser())(... = list(x = 1, y = 2))
b()> match.call(expand.dots=F)$...
list(x = 1, y = 2)
b()> is.call(match.call(expand.dots=F)$...)
[1] T
b()> names(match.call(expand.dots=F)$...)
[1] ""  "x" "y"
b()> as.character(match.call(expand.dots=F)$...)
[1] "list" "1"    "2"


(Feel free to let me know whether or not minor incompatibilities like this 
are of interest to the R-developers -- I don't know to what degree people 
are trying to make R compatible with S-plus.)

-- Tony Plate

 > version
          _
platform i386-pc-mingw32
arch     x86
os       Win32
system   x86, Win32
status
major    1
minor    4.1
year     2002
month    01
day      30
language R
 > 

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel 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-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._