Names of Greek letters stored as character strings; plotmath.
... and here is another incantation that may be informative.
xnm<- as.name("gamma') ## This does the parsing
plot(0, xlab =bquote(.(xnm))
The initial puzzle is that if you just set
xnm <- "gamma"
bquote will insert the string "gamma" rather than the symbol. After
all, that's what plotmath sees for xnm. So the key is telling plotmath
that it's a symbol, not a string. This can either be done before, as
above, or inline, as you and Gabor showed. Unsurprisingly. this also
does it, since as.name() is doing the parsing:
xnm <- "gamma"
plot(0,xlab=bquote(.(as.name(xnm))))
AND we are adhering to Thomas's dictum: bquote is a wrapper for
substitute(), which is what he recommends as the preferable
alternative to eval(parse(...)) . But, heck -- all such software
principles are just guidelines. Whatever works (robustly).
HTH.
Cheers,
Bert
On Sat, May 19, 2012 at 3:17 AM, Gabor Grothendieck
<ggrothendieck at gmail.com> wrote:
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
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm