Rob Hall
Rob Hall

Reputation: 1418

R: adding to an existing expression()

Assume you have an existing expression() in R, e.g.

 myExpression <- expression(x^2)

and wish to add <= to it without completely redefining the expression. So I am looking for a command that looks something like

myExpression <- bquote(phantom()<=.(myExpression))

The above does not work properly, which you can easily verify using

plot(1,1, main=myExpression)

The result should be

expression(phantom()<=x^2))

Upvotes: 2

Views: 70

Answers (1)

G. Grothendieck
G. Grothendieck

Reputation: 269491

Try this

myExpression <- expression(x^2)
plot(1, 1, main = bquote(phantom()<=.(myExpression[[1]])))

enter image description here

Upvotes: 4

Related Questions