R-alpha: expression(..) objects -- c(ex1, ex2) `fails'
Martin Maechler
Martin Maechler <maechler@stat.math.ethz.ch>
Mon, 3 Nov 1997 18:54:13 +0100
When investigating the
legend(x,y, expression ( <math>, <math> ), ....)
[as suggested by Jim Lindsey],
I once again stumbled over the fact that expression objects behave somewhat
``wierdly'', IMHO.
We can have expressions of length(.) > 1, and access elements of these like
list elements.
However, other natural things don't work with expressions; some example code:
##-- `Simple' length--1 expressions:
ex1 <- expression(hat(beta) == (X^t * X)^{-1} * X^t * y)
ex2 <- expression(bar(x) == sum(over(x[i], n), i==1, n))
ex3 <- expression(paste(over(1, sigma*sqrt(2*pi)), " ",
plain(e)^{over(-(x-mu)^2, 2*sigma^2)}))
##-- A length--2 expression:
ex12 <- expression(bar(x) == sum(over(x[i], n), i==1, n),
hat(x) == median(x[i], i==1,n))
mode(ex12) # expression
length(ex12)# 2
mode(ex12 [1]) # expression
mode(ex12[[1]]) # call
length(ex12[1])# 1
ex12 == ex12[1:2] #> TRUE TRUE
mode(c(ex1,ex2))#> "list" --->> This should be "expression" I think ...
## ---------------------------
mode(ex.12 <- as.expression(c(ex1,ex2))) # "expression"
## but the wrong one:
length(ex.12)# [1] 1
ex.12 #-- still has 'list(..)' in it...
###-> How could I take ex1, ex2 and "concat" them to an expression
### of length 2 ?
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=