简体   繁体   English

在RStudio项目中同时加载本地和全局.Rprofile

[英]Load both local and global .Rprofile in an RStudio project

I am working with several projects in Rstudio that require different .Rprofile files. 我正在Rstudio中使用多个需要不同.Rprofile文件的项目。 These files usually consist of two parts: global settings I'd like to have every time I run R and local project-specific settings that are loaded when I open the project. 这些文件通常由两部分组成:每次运行R时我都希望拥有的全局设置,以及在打开项目时加载的局部于项目的特定设置。

It is natural to exclude the global part from local .Rprofile s to keep it flexible. 从本地.Rprofile排除全局部分是很自然的,以保持灵活性。 However, the relevant topic in the documentation states the following (backed up by this question ): 但是, 文档中的相关主题指出以下内容( 此问题支持):

When starting RStudio in an alternate working directory the .Rprofile file located within that directory is sourced. 在备用工作目录中启动RStudio时,将找到该目录中的.Rprofile文件。 If (and only if) there is not an .Rprofile file in the alternate directory then the global default profile (eg ~/.Rprofile) is sourced instead. 如果(且仅)在备用目录中没有.Rprofile文件,则将改为使用全局默认配置文件(例如〜/ .Rprofile)。

How do I force to load the global .Rprofile at all times? 我如何一直强制加载全局.Rprofile

Small example. 小例子。 I currently have 2 .Rprofile s: 我目前有2个.Rprofile

  1. cat("global\\n"); cat("local_1\\n) cat("global\\n"); cat("local_1\\n) for project 1; 项目1的cat("global\\n"); cat("local_1\\n) ;
  2. cat("global\\n"); cat("local_2\\n) cat("global\\n"); cat("local_2\\n) for project 2; 项目2的cat("global\\n"); cat("local_2\\n) ;
  3. The global .Rprofile does not exist. 全局.Rprofile不存在。

I'd like to have 3 of them: 我想拥有3个:

  1. cat("local_1\\n) for project 1; 项目1的cat("local_1\\n) ;
  2. cat("local_2\\n) for project 2; 项目2的cat("local_2\\n) ;
  3. cat("global\\n") at the home dir. 目录目录中的cat("global\\n")

How should I tinker with these files and/or Rstudio options to get the same output on startup of both projects? 在两个项目启动时,如何修改这些文件和/或Rstudio选项以获得相同的输出?

This is just how R works (ie, the behaviour is not specific to RStudio) -- it sources only one of the .Rprofile s available. 这就是R的工作方式(即,行为并不特定于RStudio)-它仅提供.Rprofile之一。 AFAIK this is not configurable unfortunately -- see ?Startup for full details on what R does on startup. 不幸的是,这是不可配置的-有关R在启动时的作用的完整详细信息,请参见?Startup启动。

If you want to load both, I think you'll have to explicitly source the global .Rprofile from any local .Rprofile s. 如果要同时加载这两者,我认为您必须从任何本地.Rprofile显式地获取全局.Rprofile

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

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