4

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 .Rprofiles 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 (e.g. ~/.Rprofile) is sourced instead.

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

Small example. I currently have 2 .Rprofiles:

  1. cat("global\n"); cat("local_1\n) for project 1;
  2. 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?

Community
  • 1
  • 1
tonytonov
  • 25,060
  • 16
  • 82
  • 98
  • @hrbrmstr I've included that link to the question, so I'm aware of that q. And I do not agree it is a dupe, since I need them _both_ to be loaded. I have no problem loading any of them separately, which is an issue in the linked q. – tonytonov Oct 23 '14 at 09:56

1 Answers1

4

This is just how R works (ie, the behaviour is not specific to RStudio) -- it sources only one of the .Rprofiles 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 .Rprofiles.

Kevin Ushey
  • 20,530
  • 5
  • 56
  • 88
  • I was afraid this is so. Sourcing the global one seems a decent workaround though, thought of it myself. Thanks! – tonytonov Oct 24 '14 at 06:03