[Rd] ?bquote

Gabor Grothendieck ggrothendieck at gmail.com
Sat Feb 11 03:05:39 CET 2006

On 10 Feb 2006 12:15:10 +0100, Peter Dalgaard <p.dalgaard at biostat.ku.dk> wrote:
> Gabor Grothendieck <ggrothendieck at gmail.com> writes:
> > ?bquote says it returns an expression but, in fact, it typically
> > (though not always) returns a call object:
> >
> > > class(bquote(a+b))
> > [1] "call"
> >
> > > class(bquote(1))
> > [1] "numeric"
> Unevaluated expressions and objects of mode "expression" are not the
> same thing. The latter is effectively a list wrapping one or more of
> the former.
> Unevaluated expressions are generally mode "call", except when they
> are constants. They do, however, correspond to expressions as
> syntactic element (look for "expr" inside gram.y in the sources).
> The terminology does not seem completely rationalised, see also the
> help pages for expression() and substitute()/quote(), and it might be
> worth cleaning it up at some point. Just requires someone with a
> sufficiently clear mind to decide on issues like whether constants
> qualify as "unevaluated calls"... (my hunch is that they don't, and
> that "unevaluated expressions" should be used throughout, but my mind
> is definitely not clear these days.)
> Another question is whether it would be desirable for bquote to return
> an "expression" object. I realized recently that
> > boxplot(rnorm(99),ylab=quote(a[1]))
> Error in title(ylab = a[1]) : object "a" not found
> and that you need expression(a[1]) instead. I think this implies that
> you'd have to use as.expression(bquote(....)) which is a bit nasty.
> I'm not sure this isn't a bug in boxplot, though.

I think this is the same issue that Berton Gunter brought up on r-help
recently with

   x <- y <- 1:10
   plot(y ~ x, main=quote(abc))

which gives an error message even though


does not.

The first case seems to be stripping off one layer so that

   plot(y ~ x, quote(quote(abc)))

is ok but just one quote is not.

More information about the R-devel mailing list