简体   繁体   中英

Load both local and global .Rprofile in an RStudio project

I am working with several projects in Rstudio that require different .Rprofile files. 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.

It is natural to exclude the global part from local .Rprofile s to keep it flexible. 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. If (and only if) there is not an .Rprofile file in the alternate directory then the global default profile (eg ~/.Rprofile) is sourced instead.

How do I force to load the global .Rprofile at all times?

Small example. I currently have 2 .Rprofile s:

  1. cat("global\\n"); cat("local_1\\n) cat("global\\n"); cat("local_1\\n) for project 1;
  2. cat("global\\n"); cat("local_2\\n) cat("global\\n"); cat("local_2\\n) for project 2;
  3. The global .Rprofile does not exist.

I'd like to have 3 of them:

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

How should I tinker with these files and/or Rstudio options to get the same output on startup of both projects?

This is just how R works (ie, the behaviour is not specific to RStudio) -- it sources only one of the .Rprofile s available. AFAIK this is not configurable unfortunately -- see ?Startup for full details on what R does on startup.

If you want to load both, I think you'll have to explicitly source the global .Rprofile from any local .Rprofile s.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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