[R] Symbolic substitution of expressions into expressions

John Maindonald john.maindonald at anu.edu.au
Wed May 9 06:07:40 CEST 2001

I inquired

> In the following
> titletxt <- substitute(paste(tx, tilde(y) == sqrt(y)),
>   list(tx="Replace y by "))
> I'd like to be able to replace e.g. sqrt(y) by a symbol or
> symbolic expression that has the effect of inserting sqrt(y)
> into the place that it occupies.  This would allow me to put an
> arbitrary expression into that position.  [One can use text() or
> mtext() etc. to place titletxt on a graph.]
> Any clues would be most welcome.

to which Peter Dalgaard helpfully replied
titletxt <- substitute(paste(tx, tilde(y) == my.y),
   list(tx="Replace y by ",my.y=quote(sqrt(y))))

This does not quite go as far as I want.

> tx2 <- expression(x^2)
> qx2 <- quote(x^2)
> tx2
> qx2

Setting my.y = qx2 places the latexed version of x^2
into the text string and hence on the graph, while 
my.y=quote(tx2) places "expression(x^2)" into the
text string.  Is there any way to get from 
expression(x^2) or the text string "x^2" to quote(x^2)?

John Maindonald.
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