[Rd] eval functions... (PR#668)
Peter Dalgaard BSA
p.dalgaard@biostat.ku.dk
22 Sep 2000 23:15:36 +0200
aprasad@fs.fed.us writes:
> Eg., the foll. extract from a function runs fine in S-PLUS but gives the error:
> Error in x[[j]] : subscript out of bounds
> in R
>
> code snippet .....
>
> attach(xd)
> resp <- "iv802"
> pickedlist <- "BD + CEC + CLAY + ERODFAC + INCEPTSL"
> lmexp <- paste(resp, " ~ ", pickedlist,sep="")
> tmpzx <- eval(lm(lmexp,data=xd))
>
> Essentially, I want to do:
> lm(iv802 ~ BD + CEC + CLAY + ERODFAC + INCEPTSL, data=xd)
> thru a function that has the parameters passed thru TclTk and Perl......
Um, I'm somewhat surprised that this gives sensible results in
Splus... It does, since Splus accepts a text string for a formula
which R does not.
[The use of eval is also unnecessary, and the sep="" is peculiar in
view of the spaces around the ~...]
In R you need to jump through an extra hoop to create a formula object
from the string representation:
lmexp <- formula(paste(resp, "~", pickedlist))
tmpzx <- lm(lmexp,data=xd)
The Splus docs explicitly say that the first argument to lm should be
a formula object, and R's behaviour is consistent with that.
--
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._