-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf
Of Bert Gunter
Sent: Saturday, May 19, 2012 7:24 AM
To: Gabor Grothendieck
Cc: r-help
Subject: Re: [R] 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