我正在运行以下代码...
#Create a list of all the files
file.list <- list.files(path="~/R/natural-language-processing/class-notes", pattern=".csv")
#Loop over file list importing them and binding them together
D1 <- do.call("rbind",lapply(file.list, read.csv, header = TRUE, stringsAsFactors = FALSE))
这是我在运行上面的 do.call
行时遇到的错误。
Error in file(file, "rt") : cannot open the connection
我试过重置我的 wd。我当前的 getwd()
是
~/R/natural-language-processing
我看过其他的
Error in file(file, “rt”): cannot open connection
最佳答案
很可能您正在尝试从工作目录而不是您调用 list.files
的目录打开文件。而是尝试
D1 <- do.call("rbind",
lapply(paste0("~/R/natural-language-processing/class-notes/",
file.list),
read.csv, header = TRUE, stringsAsFactors = FALSE))
或者,您可以在 list.files
中将 full.names
参数设置为 TRUE
以获取完整路径:
file.list <- list.files(path="~/R/natural-language-processing/class-notes",
pattern=".csv", full.names = TRUE)
关于r - 在文件中获取错误(文件, "rt"): cannot open the connection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49090622/