[英]How to automatically load settings in R on OSX? How to find R_HOME, configure Rprofile.site, etc?
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. 我有一个Macintosh,我试图自动加载包,自制函数,并在每次启动R时使用修改后的设置。我相信这可以通过一个名为Rprofile.site的文件来完成,并通过创建函数.First和.Last在那个文件中。
One problem is, I have no idea what my R_HOME directory is, what it is used for, or if it even exists. 一个问题是,我不知道我的R_HOME目录是什么,它用于什么,或者它是否存在。 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.
我目前正在从我的应用程序目录运行R.
Over the years I have come to rely on the help(Startup)
documentation as the best place to read up on this. 多年来,我已经开始依赖
help(Startup)
文档作为阅读此内容的最佳位置。 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 grok
Renviron
versus Renviron.site
and dito for Rprofile
, you appreciate the consistent behaviour across platforms. 一旦你了解了
Renviron
与Renviron.site
和dito for Rprofile
,你会欣赏跨平台的一致行为。
Michael, I too have found this topic to be a bit confusing. 迈克尔,我也发现这个话题有点令人困惑。 I'm on a Mac as well.
我也在Mac上。 I created an "Rprofile" file which has all my customizations in it.
我创建了一个“Rprofile”文件,其中包含我的所有自定义。 Here's how mine works (I don't think there is anything special about my set up):
这是我的工作方式(我不认为我的设置有什么特别之处):
HTH Bryan HTH布莱恩
If you run getwd()
, then you will see your R startup directory. 如果你运行
getwd()
,那么你将看到你的R启动目录。 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. 在mac上它通常是
/User/login_name
这是我离开我的.RProfile
地方我加载自定义函数和经常使用的包。
Also see: Useful little functions in R (to put in your .RProfile) and Expert R users, what's in your .Rprofile?… 另请参阅: R中的有用的小函数 (放入.RProfile)和Expert R用户,你的.Rprofile中有什么?...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.