工作目录设置如何影响 RStudio 中创建的 R 项目?
工作目录设置如何影响 RStudio 中创建的 R 项目?我明白了,但无法准确解释。
How does the working directory setting affect the created R project in RStudio? I get it but can't explain it exactly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
脚本引用的所有文件路径都相对于会话的当前工作目录。假设我们需要加载位于
~/my_project/file.csv
的文件。如果没有明确的工作目录,您可能需要指定完整的文件路径:但是设置了工作目录后,您可以这样做:
RStudio 也知道当前的工作目录。在一对空引号内按 Tab 键,自动完成功能将显示当前工作目录中的文件。创建或加载 RStudio 项目文件还会将工作目录设置为项目文件的当前位置。还值得记住的是,工作目录是按会话设置的,而不是按脚本设置的(当用户同时打开多个脚本并错误地期望每个脚本“记住”不同的工作目录时,这有时会导致混乱)。
All file paths referenced by a script are relative to the session's current working directory. Suppose we need to load a file located at
~/my_project/file.csv
. Without an explicit working directory, you might need to specify the full file path:But with the working directory set, you could just do:
RStudio is also aware of the current working directory. Press Tab inside a pair of empty quotes, and the autocomplete will display files in the current working directory. Creating or loading an RStudio project file also sets the working directory to the current location of the project file. It's also worth keeping in mind that that working directory is set per session, not per script (this sometimes causes confusion when users have multiple scripts open at once and mistakenly expect each script to "remember" a different working directory).