From bates@stat.wisc.edu  Fri Sep 22 22:29:52 2000
From: bates@stat.wisc.edu (Douglas Bates)
Date: 22 Sep 2000 16:29:52 -0500
Subject: [Rd] eval functions... (PR#668)
In-Reply-To: aprasad@fs.fed.us's message of "Fri, 22 Sep 2000 22:31:08 +0200 (MET DST)"
References: <200009222031.WAA23892@pubhealth.ku.dk>
Message-ID: <6rya0kdsj3.fsf@franz.stat.wisc.edu>

aprasad@fs.fed.us writes:

> I am trying to convert some S-PLUS code to R (a tcl/tk application that uses
> R)...
> here is the error I got in R (but not in S-PLUS)...so I am wondering if it is a
> bug.
> 
> 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......

I think in both R and S-PLUS you would be better off using as.formula.

> as.formula("iv802 ~ BD + CEC + CLAY + ERODFAC + INCEPTSL")
iv802 ~ BD + CEC + CLAY + ERODFAC + INCEPTSL

You may want to use Bill Venables' favorite function do.call as well.  Try

resp <- "iv802"
pickedlist <- "BD + CEC + CLAY + ERODFAC + INCEPTSL"
tmpzx <- do.call("lm", 
          list(formula = as.formula(paste(resp, "~", pickedlist)),
               data = xd))

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


[Rd] eval functions... (PR#668)
Douglas Bates