[R] Character2function

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Tue Nov 30 22:44:11 CET 1999


Alvaro Colina <acosa at ubu.es> writes:

> x_paste(a,j,b,c,j,d,sep="") 
> 
> x="data.1_myfunction(vect.1)"
> 
> I have n numeric vectors (vect.1...vect.n)
> Then, if I could evaluate the string x, I would calculate the
> result of my function in n-vectors using a loop 
> for (j in 1:n){
> x_paste(a,j,b,c,j,d,sep="")
> function.to.evaluate.string(x)
> }
> As a result, I would have n data.j objects
> 
> I've been looking for a function in R to evaluate a string
> and I haven't found anyone.
> 
> Is there any function to do that?

parse() followed by eval(), but it's generally a bad idea.

for(j in 1:n){
	v<-paste("vect.",j,sep="")
	d<-paste("data.",j,sep="")
	assign(d,myfunction(get(v)))
}

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list