From deepayan.sarkar at gmail.com  Mon Jul 16 23:46:31 2007
From: deepayan.sarkar at gmail.com (Deepayan Sarkar)
Date: Mon, 16 Jul 2007 14:46:31 -0700
Subject: [Rd] substitute and expression
Message-ID: <eb555e660707161446s9e18352h7fbe19d76948c1a7@mail.gmail.com>

Hi,

I'm trying to understand whether the use of substitute() is
appropriate/documented for plotmath annotation. The following two
calls give the same results:

> plot(1:10, main = expression(alpha == 1))
> do.call(plot, list(1:10, main = expression(alpha == 1)))

But not these two:

> plot(1:10, main = substitute(alpha == a, list(a = 2)))
> do.call(plot, list(1:10, main = substitute(alpha == a, list(a = 2))))
Error in as.graphicsAnnot(main) : object "alpha" not found

(as a consequence, xyplot(..., main = substitute(alpha)) doesn't
currently work.)

On the other hand, this works:

> foo <- function(x) plot(1, main = x)
> foo(substitute(alpha))

I'm not sure how to interpret ?plotmath; it says

     If the 'text' argument to one of the text-drawing functions
     ('text', 'mtext', 'axis', 'legend') in R is an expression, the
     argument is interpreted as a mathematical expression...

and uses substitute() in its examples, but

> is.expression(substitute(alpha == a, list(a = 1)))
[1] FALSE

-Deepayan



[Rd] substitute and expression
Deepayan Sarkar