简体   繁体   English

R脚本无法读取文件

[英]R Script Cannot Read File

I have an R script that reads a set of files in a directory. 我有一个R脚本,可以读取目录中的一组文件。 When running it, I run into the error below even though when I read the filename interactively (in the console), it works: 运行它时,即使我以交互方式(在控制台中)读取文件名,也会遇到以下错误:

Error in file(file, "rt") : invalid 'description' argument

This is the code that reads the file: 这是读取文件的代码:

 for(i in 1:length(id_vector)){

     # Pad filename with 0s
     padded_id <- formatC(i, width = 3, format = "d", flag = "0"); 

     location <- paste(getwd(),'/',directory,'/',padded_id,".csv",sep="");

     # Read input file
     data <- read.csv(location);
 }

In place of paste try file.path() 代替粘贴尝试file.path()

file.path(getwd(),directory,paste(padded_id,".csv", sep="")) file.path(getwd(),directory,paste(padded_id,“。csv”,sep =“”))

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

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