简体   繁体   English

文件中的错误(文件,“rt”):即使设置正确的路径,也无法在 r 中打开连接

[英]Error in file(file, "rt") : cannot open the connection in r even after setting right path

loading required library加载所需的库

install.packages("tidyverse")
install.packages("dplyr")
library("tidyverse")
library("dplyr")

vector for file names文件名的向量

files<- list.files(path = "C:/Users/91932/Downloads/archive (2)/Fitabase Data 4.12.16-5.12.16",pattern =".csv")

concat directory to file names将目录连接到文件名

files<-str_c("C:/Users/91932/Downloads/archive (2)/Fitabase Data 4.12.16-5.12.16",files)

applying function to each element of vector将 function 应用于向量的每个元素


> map_df(.x = files, .f = read.csv,)

in above function map_df() i am getting an error in file (file,"rt"), even after using setwd() to set path and checking using getwd() paths seems to be correct for.csv file.在上面的 function map_df() 中,即使在使用 setwd() 设置路径并检查使用 getwd() 路径似乎对.csv 文件正确之后,我在文件(文件,“rt”)中也出现错误。

why this error occurred?为什么会发生这个错误? how to avoid such errors?如何避免此类错误?

The error is because the path is wrong: you forgot the trailing slash in the path prefix in str_c .错误是因为路径错误:您忘记了str_c中路径前缀中的斜杠。 However, rather than using str_c , you can instruct list.files to give you full paths from the get-go:但是,您可以指示list.files从一开始就为您提供完整路径,而不是使用str_c

files <- list.files(
    path = "C:/Users/91932/Downloads/archive (2)/Fitabase Data 4.12.16-5.12.16",
    pattern = ".csv",
    full.names = TRUE
)

暂无
暂无

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

相关问题 文件错误(文件,“rt”):无法在 r 中打开连接 - Error in file(file, “rt”) : cannot open the connection in r 文件中的错误(文件,“rt”):无法打开连接另外:警告消息:在文件(文件,“rt”)中:无法打开文件 - Error in file(file, “rt”) : cannot open the connection In addition: Warning message: In file(file, “rt”) : cannot open file R-saemixData函数在函数环境中找不到数据“文件错误(文件,“ rt”):无法打开连接” - R - saemixData function do not find data in a function environment “Error in file(file, ”rt“) : cannot open the connection” 在文件(文件,“ rt”)中出现错误:无法打开连接 - Getting Error in file(file, “rt”) : cannot open the connection 文件错误(文件,“rt”):无法打开连接(寻找其他解决方案) - Error in file(file, "rt") : cannot open the connection (looking for another solution) 文件中出现错误(文件,“rt”):无法打开连接 - Getting error in file(file, "rt"): cannot open the connection 文件错误(文件,“rt”):无法打开连接 - Shiny - Error in file(file, "rt") : cannot open the connection - Shiny JAGS,rjags:“文件错误(modfile,”rt“):无法打开连接” - JAGS, rjags: “Error in file(modfile, ”rt“) : cannot open the connection” 无法打开文件'test.csv':没有这样的文件或目录文件中的错误(文件,“rt”):无法打开连接 - cannot open file 'test.csv': No such file or directory Error in file(file, “rt”) : cannot open the connection 文件错误(文件,“rt”):无法打开连接 - 无法打开文件&#39;specdata&#39;访问被拒绝 - Error in file(file, “rt”) : cannot open the connection - cannot open file 'specdata' access denied
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM