如何在 OSX 上自动加载 R 中的设置?如何找到R_HOME、配置Rprofile.site等?
我有一台 Macintosh,我试图自动加载包、自制函数,并在每次启动 R 时使用修改后的设置。我相信这可以通过名为 Rprofile.site 的文件并创建函数 .First 和 .Last 来完成在该文件中。
一个问题是,我不知道我的 R_HOME 目录是什么、它的用途是什么,或者它是否存在。我发现了两个函数,我认为它们都给了我它的位置,但我得到了不同的结果。
这是第一个
> Sys.getenv("R_home")
R_home
""
和第二个
> R.home()
[1] "/Library/Frameworks/R.framework/Resources"
据我所知,第二个目录在我的机器上甚至不存在。我当前正在从我的应用程序目录运行 R。
I have a Macintosh and I am trying to automatically load packages, homemade functions, and use modified setting every time I start R. I believe this can be done with a file called Rprofile.site, and by creating the functions .First and .Last in that file.
One problem is, I have no idea what my R_HOME directory is, what it is used for, or if it even exists. I found two functions that I thought both gave me its location but I am getting different results.
Here's the first
> Sys.getenv("R_home")
R_home
""
And the second
> R.home()
[1] "/Library/Frameworks/R.framework/Resources"
As far as I can tell that second directory doesn't even exist on my machine. I am currently running R from my applications directory.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
迈克尔,我也发现这个话题有点令人困惑。我也在 Mac 上。我创建了一个“Rprofile”文件,其中包含我的所有自定义内容。这是我的工作原理(我不认为我的设置有什么特别的):
Bryan
Michael, I too have found this topic to be a bit confusing. I'm on a Mac as well. I created an "Rprofile" file which has all my customizations in it. Here's how mine works (I don't think there is anything special about my set up):
HTH Bryan
如果您运行 getwd(),那么您将看到 R 启动目录。在 Mac 上,通常为
/User/login_name
这就是我将
.RProfile
留在其中加载自定义函数和常用包的地方。另请参阅:R 中有用的小函数(放入您的 .RProfile 中)
和专家 R 用户,您的 .Rprofile 中有什么?...
If you run
getwd()
, then you will see your R startup directory. On a mac it is typically/User/login_name
That is where I leave my
.RProfile
where I load custom functions and also frequently used packages.Also see: Useful little functions in R (to put in your .RProfile)
and Expert R users, what's in your .Rprofile?…
多年来,我开始依赖
help(Startup)
文档作为阅读此内容的最佳位置。按照丰富应用程序的惯例,有许多每个用户和每个站点的配置文件。乍一看似乎有点矫枉过正,但它确实是一个很好的系统。一旦您了解了Renviron
与Renviron.site
以及 dito forRprofile
,您就会欣赏到跨平台的一致行为。Over the years I have come to rely on the
help(Startup)
documentation as the best place to read up on this. There are numerous per-user and per-site configuration file as is customary for rich applications. It may seem like overkill at first but it is a really good system. And once you grokRenviron
versusRenviron.site
and dito forRprofile
, you appreciate the consistent behaviour across platforms.