[R] Variable passed to function not used in function in select=... in subset

Gabor Grothendieck ggrothendieck at gmail.com
Mon Nov 10 23:08:41 CET 2008

On Mon, Nov 10, 2008 at 4:17 PM, Wacek Kusnierczyk
<Waclaw.Marcin.Kusnierczyk at idi.ntnu.no> wrote:
> Gabor Grothendieck wrote:
>> Certainly this has been recognized as a potential problem:
>> http://developer.r-project.org/nonstandard-eval.pdf
>> however, it is convenient when you are performing
>> an analysis and entering commands directly as opposed
>> to writing a program although possibly the potential ambiguities
>> overshadow the convenience.
> in most cases, i do not see why one could not use a string literal
> passed by value instead of having an expression deparsed within the
> function, which may lead to confusing behaviour.  this would give much
> more consistent and predictable code.  this has nothing to do with the
> evaluation mechanism, which can still be lazy.
> in the case of subset, i do not really see how this design might be
> helpful, but it's easy to see how it can be harmful, examples have just

I think the thrust of your comments were already made by reference.

Regarding the convenience it occurs in expressions like this:

   iris2 <- subset(iris, select = - Species)

to create a data frame without the Species column.

Perhaps this would have better been done by allowing an optional
formula for the select clause:

   iris2 <- subset(iris, select = ~ - Species)

but I think R is stuck with what it has due to compatibility and the large
base of users yet its still possible to add functions in packages or new
functions to R so a new variant of subset would be possible in which
case one could decide to use the new function in place of the old one.

More information about the R-help mailing list