简体   繁体   中英

How to use relative paths to load .RData files from working directory?

I am trying to use the load() function to load an.RData file into my current R session. I open my code base by double clicking on the R project file in my directory and then attempt to load the.RData file by running load('./Data/mydata.rdata') . However, this returns a 'No such file or directory' error. I verified that the working directory is correct by using getwd() .

I figure I must be using incorrect syntax because I have no issues loading the file when I type in the full file path.

Working directory for R Project file: "/Users/Me/Library/OneDrive/RStuff"

Directory containing.RData file: "/Users/Me/Library/OneDrive/RStuff/Data"

Code that works: load("/Users/Me/Library/OneDrive/RStuff/Data/mydata.rdata")

Code that fails: load('./Data/mydata.rdata')

Do relative paths not work with load() or is my syntax wrong?

Do relative paths not work with load() or is my syntax wrong?

It looks like there is an error with your paths. You said the working directory is "/Users/Me/Library/OneDrive/RStuff"

But according to the code that works:

load("/Users/Me/Library/OneDrive/RStuff/Data/mydata.rdata")

...the data file is in "/Users/Me/Library/OneDrive/RStuff/Data"

Therefore to use relative paths, you would use:

load("./Data/mydata.rdata")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM