简体   繁体   English

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

[英]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.此代码一直适用于我以前版本的 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. 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.我指向顶层目录,然后代码向下遍历文件夹结构并拉出程序的rest要使用的所有数据文件。

Also want to mention that I am not that well versed in R, so I may not be doing everything in the best manner.还想提一下,我对 R 不是很精通,所以我可能不会以最好的方式做所有事情。 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.这是我到 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)
}

I found a solution.我找到了解决方案。 I have been using read.csv from base R.我一直在使用来自基础 R 的 read.csv。 I installed the readr package and tried read_csv and it is working fine.我安装了阅读器 package 并尝试了 read_csv,它工作正常。 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.不知道为什么 read.csv 不再有效,但从我在线阅读的内容来看,对于大型数据文件,read_csv 是一个更好的选择。 Thanks to everyone that tried to help me.感谢所有试图帮助我的人。 I appreciate your time!我很感激你的时间!

暂无
暂无

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

相关问题 文件(文件,“rt”)中的错误:调用函数时“描述”参数无效 - Error in file(file, "rt") : invalid 'description' argument , when calling the function R闪亮:文件错误(文件,“ rt”):无效的“描述”参数 - R shiny: Error in file(file, “rt”) : invalid 'description' argument for(seq_along(data_file)中的i:file(file,“ rt”)中的错误:无效的&#39;description&#39;参数 - for(i in seq_along(data_file): Error in file(file, “rt”) : invalid 'description' argument 文件错误(文件,“rt”):complete.cases 程序中的“描述”参数无效 - Error in file(file, "rt") : invalid 'description' argument in complete.cases program 文件错误(描述 = xlsxFile):使用 lapply 时“描述”参数无效 - Error in file(description = xlsxFile) : invalid 'description' argument when using lapply gzfile(fname,open =“ rt”)中的错误:无效的&#39;description&#39;参数 - Error in gzfile(fname, open = “rt”) : invalid 'description' argument 文件错误(文件):运行时无效的“描述”参数 R 图库示例 - Error in file(file) : invalid 'description' argument when running R graph gallery example 文件中的错误(文件,ifelse(追加,“a”,“w”)):无效的“描述”参数 - Error in file(file, ifelse(append, “a”, “w”)) : invalid 'description' argument 如何解决错误“文件错误:无效的&#39;description&#39;参数? - How to resolve error " Error in file : invalid 'description' argument? 在rbind中读取CSV文件时遇到麻烦,“ rt”类错误 - trouble with reading csv file in rbind, “rt” kind of mistake
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM