[R] How do one modify an expression?

Prof Brian D Ripley ripley at stats.ox.ac.uk
Tue Jul 3 08:36:42 CEST 2001


On Tue, 3 Jul 2001, Uwe Ligges wrote:

>
>
> Henrik Bengtsson wrote:
> >
> > I am using expressions to annotate x and y labels in plots. I start of with
> > a label as
> >
> >   xlab <- expression(X)
> >
> > Note that it is the user that sets this. It could also be something more
> > complicated as expression(sqrt(R*G)). Can I easily add a log[2] "around"
> > this expression? I would like to get
> >
> >   xlab <- expression(log[2](X))
> >
> > I basically know nothing about expressions.
>
> The following seems to work:
>
>   plot(1:10, xlab= expression(log[2](X)))

He wants

X <- expression(sqrt(R*G))
xlab <- ???
plot(1:10, xlab=xlab)

to give the same result as

plot(1:10, xlab=expression(log[2](sqrt(R*G))))

I believe.  Try

xlab <- substitute(log[2](foo), list(foo=X[[1]]))
plot(1:10, xlab= xlab)

If this is not exactly what is required, I am sure substitute is the right
tool.

Note: I would have used

X <- quote(sqrt(R*G))
xlab <- substitute(log[2](foo), list(foo=X))
plot(1:10, xlab= xlab)

and avoided the expression().

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list