Rolf Turner
2012-May-19 05:18 UTC
[R] Names of Greek letters stored as character strings; plotmath.
I had such good luck with my previous question to r-help, (a few minutes ago) that I thought I would try again with the following query:> Suppose I have > > xNm <- "gamma" > > I would like to be able to do > > plot(1:10,xlab = <something involving xNm">) > > and get the x axis label to be the Greek letter gamma > (rather than the literal text string "gamma"). > > Is this possible? I've messed around with substitute() > and bquote() and got nowhere.Then, just before clicking on "Send", I had one more thimk, and blow me down, I got something that worked: plot(1:10,xlab=eval(expression(parse(text=xNm)))) This is another counter example to my colleague Thomas Lumley's dictum expressed in fortune("parse"). :-) I had to try several permutations of "eval" and "expression" and "parse", but I finally found that the permutation presented above does what I want. (Clearly I have no real idea what I'm doing, just hammering and hoping, but it's amazing how far hammer and hope will get you sometimes with R!) Just thought I'd post this in case it might be helpful to others. Also to see if anyone can tell me a better/slicker/sexier way to get to the same result. cheers, Rolf Turner
Gabor Grothendieck
2012-May-19 10:17 UTC
[R] Names of Greek letters stored as character strings; plotmath.
On Sat, May 19, 2012 at 1:18 AM, Rolf Turner <rolf.turner at xtra.co.nz> wrote:> > I had such good luck with my previous question to r-help, (a few minutes > ago) that I thought I would try again with the following query: > >> Suppose I have >> >> ? ?xNm <- "gamma" >> >> I would like to be able to do >> >> ? ?plot(1:10,xlab = <something involving xNm">) >> >> and get the x axis label to be the Greek letter gamma >> (rather than the literal text string "gamma"). >> >> Is this possible? ?I've messed around with substitute() >> and bquote() and got nowhere. > > > Then, just before clicking on "Send", I had one more thimk, and blow > me down, I got something that worked: > > plot(1:10,xlab=eval(expression(parse(text=xNm)))) >That can be shortened to: plot(0, xlab = parse(text = xNm)) -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com