繁体   English   中英

文件错误(文件,“rt”):读取 csv 文件时“描述”参数无效

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

我以前看过关于这个问题的帖子,但没有一个完全像我遇到的问题。 此代码一直适用于我以前版本的 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. 数据文件都具有相同的文件名。 我指向顶层目录,然后代码向下遍历文件夹结构并拉出程序的rest要使用的所有数据文件。

还想提一下,我对 R 不是很精通,所以我可能不会以最好的方式做所有事情。 任何人都可以提供的任何建议将不胜感激。

这是我到 select 顶级文件夹的代码,搜索这些文件夹,然后读取产生错误的文件。

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)
}

我找到了解决方案。 我一直在使用来自基础 R 的 read.csv。 我安装了阅读器 package 并尝试了 read_csv,它工作正常。 不知道为什么 read.csv 不再有效,但从我在线阅读的内容来看,对于大型数据文件,read_csv 是一个更好的选择。 感谢所有试图帮助我的人。 我很感激你的时间!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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