[R] iterating over files in a directory with R

Duncan Murdoch dmurdoch at pair.com
Sun Feb 8 22:33:21 CET 2004

On Sun, 8 Feb 2004 16:07:44 -0500, you wrote:

>I'm an R newbie and was wondering whether there are R commands for iterating over files in a directory.  Basically what I want to do is to iterate over many files and apply some R functions to each file seperately.  

The apply() and related functions do iteration over various things,
and list.files() and choose.files() select files (the latter
interactively on Windows).

So something like this might do what you want:

 lapply(list.files(), function(x) paste('filename is ',x))

Duncan Murdoch

More information about the R-help mailing list