如何使用相对路径从工作目录加载.rdata文件?

发布于 2025-01-25 08:01:26 字数 690 浏览 5 评论 0原文

我正在尝试使用load()函数将.rdata文件加载到当前的R会话中。我通过双击目录中的R项目文件打开代码库,然后尝试通过运行load('./ data/mydata.rdata')来加载.rdata文件。但是,这会返回“没有此类文件或目录”错误。我通过使用getwd()验证了工作目录是正确的。

我认为我必须使用错误的语法,因为当我输入完整文件路径时,我没有加载文件的问题。

R项目文件的工作目录:“/users/me/librare/oneDrive/rstuff”

包含.rdata文件的目录:”/users/users/me/m i/library/oneedrive/rstuff /data“

有效的代码: load(“/users/me/me/library/oneedrive/rstuff/data/mydata.rdata”)

diff fife diff> 代码:< /strong> load('./ data/mydata.rdata')

相对路径是否与load() 或我的语法是错误的?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

留蓝 2025-02-01 08:01:26

相对路径不适用于load()还是我的语法错误?

看起来您的路径有错误。您说工作目录是“/users/me/library/oneDrive/rstuff”

但根据有效的代码:

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

...数据文件在中“/users/me//库/oneDrive/rstuff/data“

为了使用相对路径,您将使用:

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

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")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文