[R] Reading tables using a truncated name

Dieter Menne dieter.menne at menne-biomed.de
Tue Nov 11 18:47:52 CET 2008


 <chibco <at> gmail.com> writes:

> I am trying to read a bunch of csv files using read.table() that are named
> "test_xxxxxx.csv" where "xxxxxx" has no particular pattern. Is there a way
> of reading all the files by specifying a truncated file name e.g. "test_"
> with some wild card characters, or would I have to laboriously create some
> vector with the "xxxxxx" names and iterate or lapply() over it?


Well, it's probably not that laborious; the example use a slightly different 
pattern from your's for testing. It's anyway a good idea to factor
out the processing of the file, so you end up with:

datafiles = dir(patter="nwu(.*).dat")
for(datafile in datafiles)
  processFile(datafile)




Dieter



More information about the R-help mailing list