[英]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.