Newbie question: 'File does not exist' error when loading data

Hi everyone,

Newbie question. Am attempting to import a number of datasets that have been placed in the 'data' folder of my working directory. When attempting to execute numerous dataset loading functions eg read_csv, read.xlsx I'm getting the same error message that the 'File does not exist'. The commands are being run out of a .RMD script. The file names are correct. Correct libraries are loaded readxl, readr, openxlsx etc
An example of the code is:

iris08 <- read.xlsx("data/iris.xlsx", sheet = "iris")

The working directory is correct and I've amended the working directory through RStudio and through setwd(). When I change the wd to the 'data' and remove 'data/' from the above script it loads fine. Am running RStudio 4.0.5 on macOS 11.5.2. Have exited and restarted with a new session.

Any thoughts or experience in this?

curious what you see when you run


Thanks nirgrahamuk

[1] "/"

ok, nothing suspicious there.
How about making your script print out where it thinks the working directory is. i.e. print(getwd())
what the contents are i.e. you can use list.dirs()

> print(getwd())
[1] "/Users/royden/Master of Data Science /MATH2405 - Data Wrangling"

which is expected and the output for 'list.dirs()' is also as expected.

Having same trouble exporting files as well with 'save' and 'saveRDS' commands: Error in gzfile(file, mode) : cannot open the connection

additionally you can use
file.exists() to check for mere existance
file.access() to check permissions on an existant file, using mode 4, for read access


if result is zero you have access if -1 , then you dont

Thanks nirgrahamuk
[1] TRUE

> file.access('data/iris.csv', 4)

All seems good.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.