typeof ( substitute(expression(),..) ) -- musings

Martin Maechler Martin Maechler <maechler@stat.math.ethz.ch>
Tue, 29 Jun 1999 18:27:15 +0200


[Relates to  math text / normal text mixing in plots ..]

Peter, I knew you'd know the answer quickly...

Anyway, one needs to be somewhat careful here [R version  pre 0.64.2]:

    typeof(print( e1 <-            expression(a + b))) # expression 
    typeof(print(se1 <- substitute(expression(a + b), list(a = 1)))) # language

    length(e1) # == 1
    length(se1)# == 2

    text.e <- function(x,y,e) {
        text(x,y,paste(deparse(substitute(e)),": "),adj=c(1,0))
	text(x,y,e, adj=0)
    }
    plot(1,type="n", axes= F)
    text.e(1,1.4, e1); text.e(1,1.3, se1); text.e(1,1.2, se1[[2]])

Which shows that you can't use the result of `substitute' directly, but
rather the 2nd element [[which is *still* not an expression !!]]

This is all +- S-plus (3.4) compatible 
     {{some details are NOT compatible; e.g. 
	     as.expression(se1[[2]])
       gives `what you expect' in R, but not in S-plus 3.4 or 5.0r3
     }}

  e1 is an expression	whereas
 se1 is a  call (aka "language" in R).

----
Is this documented anywhere? [blue book; language reference; ?? ]

Martin
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._