Skip to content
Prev 12099 / 398502 Next

How do one modify an expression?

On Tue, 3 Jul 2001, Uwe Ligges wrote:

            
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().