Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reload .Renviron or .Rprofile from an active R session (without restarting R)?

Tags:

r

When R starts (with default options), it loads the .Rprofile and .Renviron files in the working directory or user's home directory. In my case these files may be changed during the course of the R session (e.g. as packrat does). I was wondering if there is a way to ask R to simply refresh its .Renviron having to quit and restart R?

For instance, in the case of .Rprofile, it is sufficient to simply source(".Rprofile") to reload the .Rprofile from the working directory. Can something similar be managed for .Renviron?

like image 369
cboettig Avatar asked May 29 '14 16:05

cboettig


People also ask

How do I reload in R?

You can restart R by clicking on Session -> Restart R (top menu).

How do I restart an R session from the console?

If you use RStudio, use the menu item Session > Restart R or the associated keyboard shortcut Ctrl+Shift+F10 (Windows and Linux) or Command+Shift+F10 (Mac OS).

How do I remove files from startup in R?

7.3 Disabling startup files You can run R without any startup files by using the --vanilla argument when starting R. In RStudio you can do this by checking the option Project Options -> Disable . Rprofile execution on session start / resume .

Where do I put the .renviron file?

These files are set for each version of R and should be located in R_HOME/etc/ . You can find R_HOME by running the command R.


1 Answers

Use readRenviron Reference: http://stat.ethz.ch/R-manual/R-devel/library/base/html/readRenviron.html

Yes I remember getting stuck on Sys.getenv a while ago. and thanks to your question, it reminded me about packrat. Going to use it to distribute some code for a manuscript.

like image 57
infominer Avatar answered Oct 05 '22 19:10

infominer