0

When I'm calling any read.___() function in R it is looking at the wrong file path. I have tried changing the working directory multiple times and it keeps going to the same path. For example I'm trying the following:

setwd("C:/OneDrive/")
read.csv("~/Desktop/Data/file.csv")

I then get the following error:

Error in file(file, "rt") : cannot open the connection In addition: Warning message: In file(file, "rt") : cannot open file 'C:/OneDrive/Documents/Desktop/Data/file.csv': No such file or directory

For some reason the read() function adds the documents folder in place of the specified working directory. I tried uninstalling and deleting all files related to R on my computer then reinstalling. I still get the same issue. I've seen others ask a similar question, but everyone keeps telling them to set the working directory to something different. It doesn't matter what I set the working directory to. R keeps adding the Documents folder into the path. How do I get it to stop adding the Documents folder?

  • 4
    Using `~` is just a shorthand for absolute path to environment path variable. See [Tilde "~" expression not functioning in "R"?](https://stackoverflow.com/q/34400903/1422451) – Parfait Apr 17 '22 at 17:56
  • See what `path.expand("~/Desktop/Data/file.csv")` gives. It's probably that filename. – Rui Barradas Apr 17 '22 at 18:40

0 Answers0