简体   繁体   中英

Error in file(file, "rt") : invalid 'description' argument when reading csv files

I have seen posts about this issue before, but none exactly like the issue that I am having. This code has been working for me with previous versions of R. I recently updated my R and R Studio to versions R 4.2.1 and RStudio Desktop 2022.07.1+554, and now I am getting the subject error when I try to read in my data files. The data files all have the same filenames. I point to the top level directory and then the code goes down through the folder structure and pulls out all of the data files to be used by the rest of the program.

Also want to mention that I am not that well versed in R, so I may not be doing everything in the best manner. Any suggestions that anyone can provide would be most appreciated.

Here is my code to select the top level folder, search through those folders and then read the files which is generating the error.

wd <<- choose.dir(caption = "Select top level folder where your data is located")
setwd(wd)

#List the full path and filename of all files in the working directory and sub-directories that starts 
#with "DINum" and ends with ".csv"
out_files <- list.files(pattern = "^DINum(.*)csv$", recursive = TRUE)

# initialise list to store csv files
list.data <- NULL

# create a loop to read in data
for (i in 1:length(out_files))
{
  list.data[[i]]<-read.csv(out_files[i], check.names = TRUE)
}

I found a solution. I have been using read.csv from base R. I installed the readr package and tried read_csv and it is working fine. Not sure why read.csv no longer works, but from what I read online, read_csv is a better choice anyway for large data files. Thanks to everyone that tried to help me. I appreciate your time!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM