Configuring RRO for Reproducible Research · MRAN Skip to main content

Configuring RRO for Reproducible Research

Introduction

While R’s default behavior of saving and later reloading your workspace may seem like a convenience to some users, this behavior can be a significant hindrance to those who are interested in reproducible research. For example, when you reload a saved workspace, you may inadvertently use artifacts from an older version of your R code. Or, your code might call a package that was previously installed, but might not otherwise be available on another’s machine or if you hadn’t reloaded your own workspace. Any of these cases would create reproducibility issues across time and users.

For this reason, we recommend that you disable the save and reload feature in R. In this way, you are sure you are working in a clean environment that offers reproducible results by anyone with the same package versions.

Important! If you choose to disable this behavior, please note that you must disable it in each place from which you start R, such as your IDE, the R GUI, or your terminal window.

Disabling in the RGui

For Windows Users

To disable the saving of the workspace, you must modify the Rprofile.site file to override default q() and quit() behavior, as such:

Important! You MUST have administrator rights to the Rprofile.site file to edit it.
  1. Open the file C:\Program Files\Microsoft\R Open\R-3.4.0\etc\Rprofile.site.

  2. Append the following code to the end of that file.

    utils::assignInNamespace("q", 
       function(save = "no", status = 0, runLast = TRUE) {
         .Internal(quit(save, status, runLast))
       }, "base")    
    
    utils::assignInNamespace("quit", 
       function(save = "no", status = 0, runLast = TRUE) {
         .Internal(quit(save, status, runLast))
       }, "base")
  3. Save the file.

Now R will never save or prompt you to save your workspace when you exit R from your R Console unless you manually remove this code.

For Mac Users

To disable the saving of the workspace, you must edit the preferences in the R Console as follows:

  1. Launch Microsoft R Open. The R Console appears.
  2. Choose R > Preferences from the menus.
  3. Under the General title, click Startup. The Startup dialog appears.
  4. Locate the option to Save workspace on exit from R.
  5. Select the No radio button option to disable the save on exit.
  6. Exit from the dialog.

Now R will never save or prompt you to save your workspace from the R Console unless you manually change this option.

Disabling in RStudio

To disable this save behavior in RStudio, do the following:

  1. With RStudio running, choose Tools > Global Options from the menus.
  2. In the Options dialog, change the value for Save workspace to .RData on exit to Never.
  3. Click OK to apply the change and close the dialog.

Now R will never save or prompt you to save your workspace from RStudio unless you manually change this option.

Disabling in the Command Line/Terminal Window

Note: You must disable this feature manually each time you start R on the command line. The change is only applicable to that R session.

To disable the prompt to save the workspace image on the command line, do the following each time you start R:

R --no-save

Now, R will not save or prompt you to save the workspace when your session ends. Note that you will have to use R --no-save each time you launch R to disable workspace saving: consider creating an alias.