[R] substituting string variable in expression with its value

Jannis bt_jannis at yahoo.de
Thu Sep 12 13:46:58 CEST 2013


Hi,


the following code works:

plot(1,1, main=expression(paste("speed [", m * s^{-1}, "]")))


I would, however, like to be able to supply the value "speed" and 
m*s^{-a} by variables, e.g. do something like:


a = 'speed'
b = 'm*s^{-2}'

plot(1,1, main=expression(paste(a, " [", b, "]")))

This, however, does not work as a and b are not treated as variable 
names in this case. Does anyone have a solution for this?


Cheers
jannis



More information about the R-help mailing list