Skip to content
Prev 179991 / 398506 Next

Read many .csv files into an R session automatically, without specifying filenames

Hi,

I once made this function (essentially the same as Romain),


assignFiles <-
function (pattern = "csv", strip = "(_|.csv|-| )", ...)  # strip is  
any pattern you want to remove from the filenames
{
     listFiles <- list.files(pattern = pattern, all.files = FALSE,
         full.names = FALSE, recursive = FALSE)
     variables <- gsub(strip, "", listFiles)
     for (ii in (1:length(listFiles))) {
         name <- listFiles[ii]
         assign(variables[ii], read.csv(name, ...), env = .GlobalEnv)
     }
}


HTH,

baptiste
On 11 May 2009, at 22:55, Romain Francois wrote:

            
_____________________________

Baptiste Augui?

School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK

Phone: +44 1392 264187

http://newton.ex.ac.uk/research/emag