Skip to content
Prev 295049 / 398506 Next

Names of Greek letters stored as character strings; plotmath.

On Sat, May 19, 2012 at 11:07 AM, William Dunlap <wdunlap at tibco.com> wrote:
Bill's point is on the money here. We should aim to teach one way that
works always. But finding that one way is the hard part for me.

Lately, I'm bothered that R (or computers in general?) allows too many
ways to do the same thing that work SOME of the time. Without a very
deep understanding of the terminology, users are bewildered.

Go read ?plotmath.  Do we see "as.name"?   NO.  Why does the idiom
expression(paste()) work as well?   (Don't answer, that's a rhetorical
question).

There are too many ways to do the same thing. Or, well, too many of us
know one way that works sometime and don't find out it doesn't always
work until, as Bill says, it is buried in the bottom of some big
function that behaves erratically.

Gabor notes this works (sometimes):

plot(0, xlab = parse(text = xNm))

Bert observes this works (sometimes)

xnm <- quote(gamma)
## makes xnm the name gamma not the string "gamma"
plot(0,xlab = bquote( .(xnm))

Bill observes this works:
xnm <- "gamma"
plot(0,xlab = bquote(.(as.name(xnm))))

In line with that, Bill suggests:

power <- "gamma" ; x <- "Waist Size (cm)" ; y <- "Weight (kg)" # invalid R names
plot(0, main=bquote(.(as.name(x))^.(as.name(power))/.(as.name(y))))

It appears to me that 2/3 of the as.name usages are not needed, at
least not in R 2.15 on Debian Linux.

This works just as well

plot(0, main=bquote(.(x)^.(as.name(power))/.(y)))


Is there any important reason to wrap x and y in this command with as.name?

It does work, maybe I be in the general habit of wrapping as.name
around variables in bquotes?  I'm more confused.

The good new for me is that I cannot find any replacements for the
usage of "as.name" in that particular expression. So there is just one
way.

Oh, wait, I spoke too soon. as.symbol is identical to as.name.

plot(0, main=bquote(.(x)^.(as.symbol(power))/.(y)))

And then, logically, this works:

plot(0, main=bquote(.(x)^.(as.vector(power, "symbol"))/.(y)))

I personally think "as.symbol" is more likely to be understood by
students, I may stick to that. So I think the most succinct, best
approach is


plot(0, main=bquote(.(x)^.(as.symbol(power))/.(y)))

or perhaps the most consistent-looking strategy is:

power <- as.symbol("gamma") ; x <- "Waist Size (cm)" ; y <- "Weight (kg)"
plot(0, main=bquote(.(x)^.(power)/.(y)))

Speaking of commands that have identical results and exist separately
for no apparently good reason:

library(help=rockchalk)

help(package=rockchalk)

pj

  
    

Thread (18 messages)

Rolf Turner Names of Greek letters stored as character strings; plotmath. May 18 Gabor Grothendieck Names of Greek letters stored as character strings; plotmath. May 19 Bert Gunter Names of Greek letters stored as character strings; plotmath. May 19 Bert Gunter Names of Greek letters stored as character strings; plotmath. May 19 William Dunlap Names of Greek letters stored as character strings; plotmath. May 19 Paul Johnson Names of Greek letters stored as character strings; plotmath. May 19 Gabor Grothendieck Names of Greek letters stored as character strings; plotmath. May 19 William Dunlap Names of Greek letters stored as character strings; plotmath. May 19 Rolf Turner Names of Greek letters stored as character strings; plotmath. May 19 Robert Baer Names of Greek letters stored as character strings; plotmath. May 20 Rolf Turner Names of Greek letters stored as character strings; plotmath. May 20 Duncan Murdoch Names of Greek letters stored as character strings; plotmath. May 20 Bert Gunter Names of Greek letters stored as character strings; plotmath. May 20 Joshua Wiley Names of Greek letters stored as character strings; plotmath. May 20 Duncan Murdoch Names of Greek letters stored as character strings; plotmath. May 20 Peter Dalgaard Names of Greek letters stored as character strings; plotmath. May 21 William Dunlap Names of Greek letters stored as character strings; plotmath. May 21 Bert Gunter Names of Greek letters stored as character strings; plotmath. May 21