Error in file(file, "rt") : cannot open the connection [duplicate] Error in file(file, "rt") : cannot open the connection [duplicate] r r

Error in file(file, "rt") : cannot open the connection [duplicate]


You need to change directory <- ("./specdata") to directory <- ("./specdata/")

Relative to your current working directory, you are looking for the file 001.csv, which is in your specdata directory.

This question is nearly impossible to answer without any context, since you have not provided us with the structure of your working directory here. Fortunately for you, I have already taken R Programming on Coursera, so I already did this homework question.


The reason why you see this error I guess is because RStudio lost the path of your working directory.

(1) Go to session...

(2) Set working directory...

(3) Choose directory...

--> Then you can see a window pops up.

--> Choose the folder where you store your data.

This is the way without any code that you change your working directory.Hope this can help you.

enter image description here


Set your working directory one level/folder higher. For example, if it is already set as:

setwd("C:/Users/Z/Desktop/Files/RStudio/Coursera/specdata")

go up one level back and set it as:

setwd("C:/Users/Z/Desktop/Files/RStudio/Coursera")

In other words, do not make "specdata" folder as your working directory.