[Rd] quote() vs quote(expr=)

Hadley Wickham h.wickham at gmail.com
Mon Feb 18 17:04:04 CET 2013


> If there is a bug here, I'd say that it is in str(), revealing the implementation of the missing value as the symbol ``,

Yes, a fix to str would be nice too :)

> which we otherwise try not to disclose to R code, e.g.
>
>> as.symbol("")
> Error in as.symbol("") : attempt to use zero-length variable name


> There's a difference between passing 0 arguments and passing a missing argument and I see nothing particularly wrong with quote(expr=) returning missing. It is, for instance, reasonably consistent that
>
>> eval(quote(expr=))
> Error in eval(expr, envir, enclos) : argument is missing, with no default

quote(expr =) returning missing seems like the right thing to me,
quote() throwing an error does not, because it violates the usual
semantics where f(x = ) is equivalent to f().

>> I bring this up because this seems like the most natural way of
>> capturing the "missing" symbol with pure R code, compared to
>> substitute() or bquote() or formals(plot)$x
>
> Are you sure you want to do that? I tend to think that it belongs in the "if it breaks, you get to keep both pieces" category.

You do occasionally need the missing symbol when computing on the
language (see e.g.
https://github.com/hadley/pryr/blob/master/R/partial.r for an example
of where I use it).  You do have to handle it with care, but you are
limited without it.

I think it's better to have one canonical way of getting the missing
symbol when you need it, so that it's easier to recognise in code, and
to clearly illustrates that you do want the missing symbol.  I'd
certainly accept an argument that there should be a dedicated function
to do this, rather than relying on an implementation side-effect of
quote, bquote etc.

Hadley

-- 
Chief Scientist, RStudio
http://had.co.nz/



More information about the R-devel mailing list