我在多台机器上的 Windows 下使用 R。
我知道你可以从 R 脚本中设置工作目录,就像这样
setwd("C:/Documents and Settings/username/My Documents/x/y/z")
...但是这破坏了脚本的可移植性。必须反转所有斜杠也很烦人(因为 Windows 给了你反斜杠)
有没有办法在特定的工作目录中启动 R,这样您就不需要在脚本级别执行此操作?
最佳答案
您应该将 R(R.lnk 文件)的快捷方式复制到所需文件夹。然后在“属性”(鼠标右键 - > 最后一个选项)中删除第二个选项卡(“快捷方式”?)中“开始于...”字段中的任何内容。如果您使用此快捷方式启动 R,工作目录将是快捷方式所在的目录。
我没有英文版的 Windows,所以我不确定字段名称,但它们应该很容易找到。
R-windows-faq 中有类似的问题:
2.5 How do I run it?
2.10 How can I keep workspaces for different projects in different directories?
2.14 What are HOME and working directories?
在 2.14 中提到
The working directory is the directory from which Rgui or Rterm was launched, unless a shortcut was used when it is given by the `Start in' field of the shortcut's properties.
关于r - 如何让 R 将您的工作目录识别为其工作目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1395301/