Import multiple txt files from a specific folder

My goal is to import all txt files from a specific folder into a list.

So I:

setwd(".../folder") data <- list.files(pattern = "\\.txt$") lis <- lapply(data, read.csv) 

However, I would like to avoid using setwd() . Therefore, I can do:

 data <- list.files(path = ".../folder", pattern = "\\.txt$") 

But then, of course, I get an error message. There is no such file or directory that read.csv looks in the wrong directory. How can I specify a folder in combination with importing all files into data ?

+5
source share
1 answer

Use the full.names operator in list.files .

 data <- list.files("../folder", pattern = "\\.txt",full.names = TRUE) 
+4
source

All Articles