[R] using eval-parse-paste in a loop

Erik Iverson iverson at biostat.wisc.edu
Tue Feb 26 18:28:42 CET 2008


> ############### stripping off eval, looking for clues
> 
>  
> 
> parse(paste('read.xls("Book',nam,'.xls",sheet=1,from=4,colClasses="numer
> ic")',sep=''))
> 
> Error in file(file, "r") : unable to open connection
> 
> In addition: Warning message:
> 
> In file(file, "r") :
> 
>   cannot open file
> 'read.xls("Book1.xls",sheet=1,from=4,colClasses="numeric")', reason
> 'Invalid argument'
> 

Your clue is that it looks like parseis unsuccessfully trying to open a 
file.  Look at ?parse and note the first argument, which you are using 
because of positional matching.

You want eval(parse(text = paste(...)))

Best,
Erik Iverson



More information about the R-help mailing list