1

I would like to know if there is a way when importing a file from instead of specifying the name of the document to import, just provide the name of the folder and let R import what is inside (always assuming there is only one document). Because sometimes I have the name of very large files and it would be much easier for me just to write the name of the folder. For example, now I import like this:

base_neg <- read_excel ("Data / Bases / Canonical / List_neg.xls")

But I would just like to give it "Data / Bases / Canonical /", so that it looks like this:

base_neg <- read_excel ("Data / Bases / Canonical").

Is there a function to do that?

juandmaz
  • 43
  • 6
  • Try to modify and use the solution from [this thred](https://stackoverflow.com/questions/11433432/how-to-import-multiple-csv-files-at-once) – Bart Jan 12 '22 at 08:14

1 Answers1

0

Here is the example code for the folder csv read for R

let's say you have multiple .csv files in your specific folder

## read the file name list
flist = list.files("Data/Bases/Canonical/", ".csv")

## initialize the variable
data = NULL

##
for(fi in 1:length(flist)){
   data[[fi]] = read.csv(paste0("Data/Bases/Canonical/", flist[fi]))
}

## for check
data[[1]]

I am not sure this is what you want So, please try this