[R] "Read.csv" in R with dynamic file (1st) argument

Carl Witthoft
Thu, 10 Sep 2009 23:01:06 -0000

That will not work (or at least doesn't work for me.

This does work:

fnam<-'thefilename.csv'  #or build the name however you like
fpath <- 'macintoshhd/users/me/myfolder/  # or whatever you need

read.csv(eval(paste(fpath,fnam,sep=""))  #worked for me


Carl



-----------

Try this:

read.csv(sprintf("D://R//Data//%04d//%04d.csv", x, x), header = TRUE)

On Wed, Sep 9, 2009 at 9:32 PM, Steven Kang <stochastickang at
gmail.com>wrote:

 > Dear R users,
 >
 >
 > I have numerous data sets (csv files) saved in the folder which has the
 > same
 > name as individual data.
 > (i.e data x1 saved in x1 folder, data x2 in x2 folder etc)
 >
 > I would like to read in the desired data set name using 'scan'
function and
 > assign this inputted value to an object so that it can be used in the
 > 'read.csv' function.
 >
 > For example,
 >
 > x <- scan()
 > 1: 0708
 > 2:
 > Read 1 item
 >
 > dat <- read.csv("D://R//Data//x//x.csv", head=TRUE, sep =
",")
 > Error in file(file, "r") : cannot open the connection
 > In addition: Warning message:
 > In file(file, "r") :
 >  cannot open file ('D://R//Data//x//x.csv': No such file or
directory
 >


--
Henrique Dallazuanna
Curitiba-Paran?-Brasil
25? 25' 40" S 49? 16' 22" O