Skip to content
Prev 295196 / 398506 Next

Names of Greek letters stored as character strings; plotmath.

Yet again:Thank you Peter and Duncan. I appreciate your comments and insights.

I agree wholeheartedly with Peter's comments below about understanding
what a parsed expression is in R. In R -- and in functional
programming in general, I believe -- computing on the language is
extremely handy, even for relatively basic programming.  I found V&R's
discussion in "S Programming" on "Computing on the Language" very
helpful in this regard, especially their table 3.2,  which dissects
the different but cognate situation of formulas,  functions, and
function calls. Perhaps something similar could be done for
expression(), parse(), and quote(). I think there are subtleties here
that deserve explicit mention and elaboration.

As a feeble attempt in this direction, which I hope illuminates more
than it obfuscates -- and I would greatly appreciate prompt
corrections of any errors -- perhaps the following might be useful:
########################
a <- 3
x <- quote(a+2)
y <- parse(text = "a+2")
z <- expression(a+2)
##
eval(x) ## 5
eval(y) ## the same
eval(z) ## the same
##
## Now note:
as.list(x) ## quote(a+2) the parse tree for the expression a+2
##
as.list(y) ## looks like a list whose component is the parse tree for
the expression
## as demonstrated by:
##
identical(x,y[[1]]) ##TRUE
##
as.list(z) ## appears to be the same as z. And, indeed,
##
identical(y[[1]],z[[1]])  ##TRUE. The parse tree for the expression again.
##
### However
##
identical(y,z) ## FALSE !!
## To see what's going on, use str()
str(x) ## language a + 2
str(y[[1]]) ## the same
str(z[[1]]) ## the same
##
## But
str(y) ## complex structure with attributes
str(z) ## simple expression
##########################################

To me, this reinforces Bill Dunlap's and Thomas Lumley's counsels:
avoid explicit parsing and evaluation via eval(parse(...)) in favor of
working with the parsed expression via substitute() and bquote().

HTH,

Bert
On Mon, May 21, 2012 at 12:20 AM, peter dalgaard <pdalgd at gmail.com> wrote:

  
    

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