[R] Opening all files in a directory
Mark Myatt
mark at myatt.demon.co.uk
Wed Jun 12 19:41:08 CEST 2002
MATT BORKOWSKI <mpb170 at psu.edu> writes:
>Is there any way that R can be programmed so that it will cycle through
>all files in a directory without having to define file names? The reason I ask
>is because I will have about 50-100 files in a directory which will be randomly
>named. ie: MIDEX, OACES-CO2, ODEN91, etc...
>
>If not...are there any languages out there that will do this sort of things? Or
>is
>there another method you could recommend for handling the problem?
Something like:
cycle <- function(file.path = ".", file.pattern = "*.dat")
{
files.2.process <- dir(path = file.path, pattern = file.pattern)
for(file.name in files.2.process)
{
current.file <- read.table(file.name, header = TRUE)
#
# now do something with this data ...
#
}
}
Does it for me. The file.pattern parameter takes regular expressions.
Mark
--
Mark Myatt
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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