[R] Automatic File Reading [Broadcast]
ronggui
ronggui.huang at gmail.com
Sun Oct 29 05:05:39 CET 2006
2006/10/29, Wensui Liu <liuwensui at gmail.com>:
> Andy,
>
> First of all, thanks for your solution.
>
> When I test your code, it doesn't work. I am not sure if I miss something.
>
> Here is the code I tested:
> flist<-list.files(path = file.path(, "c:\\"),pattern="[.]csv$")
First of all, I think the command should be as follows:
flist<-list.files(path = file.path("c:\\"),pattern="[.]csv$")
> csvlist<-lapply(flist, read.csv, header = TRUE)
>
> Here is the error:
> Error in file(file, "r") : unable to open connection
> In addition: Warning message:
> cannot open file 'test1.csv', reason 'No such file or directory'
Maybe your should reset working directory. the flist is the relative
path so you should set the directory where the data files are (I guess
is "c://" in your case) as working directory.
setwd("c://")
csvlist<-lapply(flist, read.csv, header = TRUE)
> Thank you so much!
>
> On 10/18/06, Liaw, Andy <andy_liaw at merck.com> wrote:
> > Works on all platforms:
> >
> > flist <- list.files(path=file.path("somedir", "somewhere"),
> > pattern="[.]csv$")
> > csvlist <- lapply(flist, read.csv, header=TRUE)
> > whateverList <- lapply(csvlist, whatever)
> >
> > Andy
> >
> > From: Richard M. Heiberger
> > >
> > > Wensui Lui asks:
> > > > is there a similar way to read all txt or csv files with same
> > > > structure from a folder?
> > >
> > >
> > >
> > > On Windows I use this construct to find all files with the
> > > specified wild card name.
> > > I used the "\\" in the file paths with the translate=FALSE,
> > > because the "/" in
> > > the DOS switches "/w/B" must not be translated. On Windows
> > > this picks up
> > > both lower and upper case filenames
> > >
> > > A similar construct can be written for Unix.
> > >
> > > tmp <- shell('dir c:\\HOME\\rmh\\tmp\\*.R /w/B', intern=TRUE,
> > > translate=FALSE) ##msdos
> > > for (i in tmp) source(paste("c:\\HOME\\rmh\\tmp\\", i, sep=""))
> > >
> > > ______________________________________________
> > > R-help at stat.math.ethz.ch mailing list
> > > https://stat.ethz.ch/mailman/listinfo/r-help
> > > PLEASE do read the posting guide
> > > http://www.R-project.org/posting-guide.html
> > > and provide commented, minimal, self-contained, reproducible code.
> > >
> > >
> > >
> >
> >
> > ------------------------------------------------------------------------------
> > Notice: This e-mail message, together with any attachment...{{dropped}}
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Ronggui Huang
Department of Sociology
Fudan University, Shanghai, China
»ÆÈÙ¹ó
¸´µ©´óѧÉç»áѧϵ
More information about the R-help
mailing list