Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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


> 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 .

why this error occurred? how to avoid such errors?

>Solution :

The error is because the path is wrong: you forgot the trailing slash in the path prefix in str_c. However, rather than using str_c, you can instruct list.files to give you full paths from the get-go:

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading