Skip to content
Prev 295047 / 398506 Next

Names of Greek letters stored as character strings; plotmath.

parse(text=paste(...)) works in simple cases but not in others.  The
fortune about it is there because it is tempting to use but if you bury it
in a general purpose function it will cause problems when people
start using nonstandard names for variables.  bquote(), substitute(),
call(), and relatives work in all cases.  E.g.,

  > par(mfrow=c(2,1))
  > power <- "gamma" ; x <- "Waist" ; y <- "Weight" # valid R variable names
  > plot(0, main=bquote(.(as.name(x))^.(as.name(power))/.(as.name(y))))
  > plot(0, main=parse(text=paste0(x, "^", power, "/", y))) # same as previous
  >
  > 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))))
  > plot(0, main=parse(text=paste0(x, "^", power, "/", y))) # whoops
  Error in parse(text = paste0(x, "^", power, "/", y)) :
    <text>:1:7: unexpected symbol
  1: Waist Size
           ^

Now you might say that serves me right for using weird variable names,
but some of us use R as a back end to a GUI system (one not designed
around R) and don't want to inflict on users R's rules for names when
we do not have to.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com

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