让 R 存储每个会话的工作目录
我在超级用户上问过这个问题,但有人建议我在这里提问,因为有更多的 R 专家。
The question:当我转到“文件”>“文件”时,我必须继续导航到我的目录。更改目录...,这特别烦人。
有谁知道如何让R记住以前使用过的目录?
I asked this on Super User, but someone suggested that I take it here because there are many more R experts.
The question:
I have to keep navigating to my directory when I go to File > Change dir..., which is particularly annoying.
Does anyone know how to make R remember the previously used directory?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我将与特定项目相关的所有代码保存在一个文件中(或更常见的是一系列文件)。第一行通常是
设置目录。
将工作区保存到所需目录后,只需打开该工作区(而不是从桌面或开始菜单)即可启动 R。那么目录已经设置到你想要的位置了。
I keep all the code associated with a particular project in a file (or more often a series of files). The first line is usually
which sets the directory.
Once a workspace has been saved in the desired directory, just start R by opening that workspace (rather than from the desktop or start menu). Then the directory is already set to where you want it.
我可能不会回答你的问题,因为它有点模糊,但有一些想法:
您可以编写一个自定义函数,在设置新目录之前记住当前目录
来自 R for Windows 常见问题解答:
I may not be answering your question, because it's a bit vague, but some thoughts:
You could write a custom function that remembers the current directory before you set the new directory
From the R for Windows FAQ:
这取决于您使用的系统。有一些技巧可以使用,但如果您希望从系统菜单运行 R 并让它记住目录,那么快速回答是否定的,这不会发生。 Linux 非常简单,只需先导航到终端中的目录即可解决问题。我对Macs一无所知,但我可以广泛地谈论Windows。首先,如果您导航到该目录并保存工作区一次,那么您可以使用保存的 .RData 文件双击并恢复您的工作区(包括当前目录)。我个人的、有偏见的观点是使用像 Notepad++ 和 NppToR 这样,当您生成 Rgui 窗口时,您将从当前脚本继承活动目录。它还提供了一个菜单命令来将工作目录调整为当前脚本的目录。
另一点是,您始终可以在任何平台上的任何 R 会话中使用 setwd("path/to/dir/") 命令设置工作目录。
This depends on the system that your using. There are a few tricks to use but if your looking to run R from a system menu and have it remember the directory the quick answer is no that won't happen. Linux is pretty easy just navigate to the directory in the terminal first and that will solve the problem. I have no idea about macs, But I can talk about windows extensively. First if you navigate to the directory and save your workspace once then you can use the saved .RData file to double click and restore your workspace including current directory. My personal, and biased opinion is to use an editor like Notepad++ with NppToR that way when you spawn a Rgui window you inherit the active directory from the current script. It also provides a menu command to adjust the working directory to the current script's directory.
Another point is that you can always set the working directory with the
setwd("path/to/dir/")
command inside any R session on any platform.我使用 StatET 和 Eclipse 作为我的 R 用户界面。它会自动将工作目录设置为我的项目文件夹的位置。工作空间 = ${project_loc}。
当从特定项目启动 R 时,它还会自动加载任何已保存的工作区。
I use StatET and Eclipse as my R user interface. It automatically sets the working directory to the location of my project folder. workspace = ${project_loc}.
It also automatically loads any saved workspace, when starting R from a particular project.
在 Windows 上,我将 code.google.com/p/batchfiles 中的文件 Rgui.bat 放入我的项目目录中,并使用它来启动 R。
On Windows, I put a file Rgui.bat from code.google.com/p/batchfiles in my project directory and use this to start R.