Martin Maechler
1997-Nov-03 17:54 UTC
R-alpha: expression(..) objects -- c(ex1, ex2) `fails'
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 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Peter Dalgaard BSA
1997-Nov-03 18:27 UTC
R-alpha: expression(..) objects -- c(ex1, ex2) `fails'
Martin Maechler <maechler@stat.math.ethz.ch> writes: [I've taken out the ">" citation symbols to allow cut and paste] ##-- `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)) ##-- A length--2 expression: ex12 <- expression(bar(x) == sum(over(x[i], n), i==1, n), hat(x) == median(x[i], i==1,n)) ##please avoid TABS, Martin. It confuses readline...> ###-> How could I take ex1, ex2 and "concat" them to an expression > ### of length 2 ?#Heh. One would at least expect l<-NULL l[[1]]<-ex1[[1]] l[[2]]<-ex2[[1]] #to be a list of calls, which by definition is what an expression is, #so you'd only need to change the mode, but: mode(e)<-"expression" e # expression(list(hat(beta) == (X^t * X)^{ # -1 # } * X^t * y, bar(x) == sum(over(x[i], n), i == 1, n))) #(Why does it deparse in that strange way, BTW?) #Also, textual representations of length-2 expressions is acting up: deparse(ex12) #[1] "bar(x) == sum(over(x[i], n), i == 1, n)" str(ex12) # bar(x) == sum(over(x[i], n), i == 1, n) dput(ex12) # bar(x) == sum(over(x[i], n), i == 1, n) deparse(ex12[[2]]) # [1] "hat(x) == median(x[i], i == 1, n)" -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-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 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=