简体   繁体   English

工作目录设置对RStudio中创建的R项目有何影响?

[英]How does the working directory setting affect the created R project in RStudio?

How does the working directory setting affect the created R project in RStudio?工作目录设置对RStudio中创建的R项目有何影响? I get it but can't explain it exactly.我明白了,但无法准确解释。

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 .假设我们需要加载位于~/my_project/file.csv的文件。 Without an explicit working directory, you might need to specify the full file path:如果没有明确的工作目录,您可能需要指定完整的文件路径:

read_csv('~/my_project/file.csv')

But with the working directory set, you could just do:但是设置了工作目录后,您可以这样做:

setwd('~/my_project/')
read_csv('file.csv')

RStudio is also aware of the current working directory. RStudio 也知道当前的工作目录。 Press Tab inside a pair of empty quotes, and the autocomplete will display files in the current working directory.在一对空引号内按 Tab,自动完成将显示当前工作目录中的文件。 Creating or loading an RStudio project file also sets the working directory to the current location of the project file.创建或加载 RStudio 项目文件还会将工作目录设置为项目文件的当前位置。 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).还值得记住的是,工作目录是根据 session 设置的,而不是根据脚本设置的(当用户同时打开多个脚本并错误地期望每个脚本“记住”不同的工作目录时,这有时会引起混淆)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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