From h.wickham at gmail.com  Mon Feb 18 17:04:04 2013
From: h.wickham at gmail.com (Hadley Wickham)
Date: Mon, 18 Feb 2013 10:04:04 -0600
Subject: [Rd] quote() vs quote(expr=)
In-Reply-To: <01CE77E8-6F40-4050-A365-A21DFF933585@gmail.com>
References: <CABdHhvGwS1xuOqYLqtJAGjJrm5gGvLW7XJs+4bg3LY_R3Z7oNQ@mail.gmail.com>
	<01CE77E8-6F40-4050-A365-A21DFF933585@gmail.com>
Message-ID: <CABdHhvHQ8uEqZ7AEhhY131=BRaUXByspdoQuc2+c3=gcBfPARw@mail.gmail.com>

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



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