[Rd] data() misbehaving inside a function

Gabor Grothendieck ggrothendieck at myway.com
Fri Oct 17 17:52:03 MEST 2003

There seem to be two opposing yet valid viewpoints to the 
question of doing it right vs. compatibility with S-Plus.
Compatbility with older version of R is a third overlapping
possible goal.

There does not appear to be an overall statement of 
intent in R, but rather, this question and others are 
approached on a case by case basis.

Scoping is an example where R took the first route and the
feature in question is an example of the second.  There 
are undoubtedly many more possible examples.  

One possibility might be to do it right, by default, but have 
a package that, when loaded, gives you S-Plus compatibility (or
visa versa).  This would cover not only this feature but other
features where there was a desire to do it right.  Some things 
that are difficult to implement in two ways, such as scoping, 
would presumably not be handled by this but other simpler items 
such as the one in question could be.

Date: Fri, 17 Oct 2003 09:28:59 +0200 
From: Martin Maechler <maechler at stat.math.ethz.ch>
[ Add to Address Book | Block Address | Report as Spam ] 
To: <Kurt.Hornik at wu-wien.ac.at> 
Cc: David James <dj at research.bell-labs.com>, <r-devel at r-project.org>,Peter Dalgaard <p.dalgaard at biostat.ku.dk> 
Subject: Re: [Rd] data() misbehaving inside a function 

>>>>> "KH" == Kurt Hornik <Kurt.Hornik at wu-wien.ac.at>
>>>>> on Fri, 17 Oct 2003 09:04:40 +0200 writes:

>>>>> Peter Dalgaard writes:
>> David James <dj at research.bell-labs.com> writes:
>>> Calls of the form data(package = pkg) inside a function 
>>> incorrectly fail ("pkg" is a local variable). For instance,
>>> foo <- function(pkg) data(package = pkg)
>>> foo("base")
>>> Error in .find.package(package, lib.loc, verbose = verbose) :
>>> none of the packages were found

>> This is pretty much unavoidable if you want a function to accept
>> unquoted names. It's not in principle different from

>> women <- "airquality"
>> data(women)

>> not being equivalent to data("airquality"). Some functions (library(),
>> require(), demo()) have a character.only argument to prevent it, and I
>> suppose we should consider putting it on help() and data() as well.

KH> Or get rid of non-standard evaluation and educate users to use quoted
KH> strings where strings should be used.

and infuriate those who know and used the S language for more
than 15 years, where help(help) has always worked? 

Definitely not worth the pain (I *know* I'd hear ... comments from them!)!
I'd go for adding `character.only'.


No banners. No pop-ups. No kidding.
Introducing My Way - http://www.myway.com

More information about the R-devel mailing list