R and RStudio using External Access rules

R and RStudio using External Access rules

For instruction on using R and RStudio using domain allowlisting (i.e., internet access based on domain instead of IP), see R/RStudio installation using domain allowlisting.

R is an open-source programming language often used by researchers and data scientists to manipulate, prepare, analyse and visualize data. RStudio is often used as the preferred IDE to write and run R code in. Some Windows VMs deployed in DRE workspaces come with R and RStudio preinstalled. If R/RStudio is not available on your VM, refer to How do I install R and RStudio? on the bottom of this article. 
The first part of the article focusses on how to make R packages available in the VMs of your workspace, which requires some one-time manual action by workspace Owners. We discuss CRAN packages (relevant for almost all R users) and Bioconductor packages (relevant for some R users) separately. 

Making CRAN packages available in your workspace

Beware: Until the instructions in this section have been followed, CRAN packages are not available. 
Only Owners can make packages available for the workspace
R code often depends on CRAN packages that are normally available on the internet. However, DRE workspaces are by default not connected to the internet, which means that packages are not available without taking some one-time manual action. In this article, we explain the steps that an Owner needs to perform to make CRAN packages available within their workspace. It is a two-step process:
  1. First, they need to create and activate External Access rules in the workspace;
  2. Then, they need to change a settings file (Rprofile.site) in the R installation of each the VM(s)
If you follow the instructions below carefully, all workspace members should be able to load and install packages on the VM(s) going forward. 

Step 1: Create and activate External Access rules

Option 1: First go to the myDRE portal, to your workspace and then to the External Access tab. Here, you need to create and activate two different External Access rules to make CRAN packages available:
RuleIP addressPortReason
CranRProject443137.208.57.37443Access to cran.r-project.org
CranRProject80137.208.57.3780Access to cran.r-project.org

For each rule:
  1. Click on the Add Rule button in the External Access tab.
  2. In the pop-up, fill in the details as shown above and click on Save. 
  3. Enable the rules.
These two rules allow connections from the VMs in your workspace to a CRAN repository mirror hosted at r-project.org. To learn more about External Access rules, refer to our article on Opening up ports.

Option 2: External access to CRAN repository mirror can also be configured using domain allowlisting. Submit a ticket to your Support team member requesting opening access to R and RStudio related domains. Please do not forget to mention your workspace name in the request. When using this option, please follow further the R/RStudio specific instructions here

Step 2: Change the Rprofile.site file of your R installation

On each of the VMs in your workspace, you need to change the Rprofile.site file. This will change the standard settings of your R installation, so that it will automatically use the CRAN mirror that you made accessible in step 1.
You can choose to change the file manually, or to replace the existing file with one that we've attached to the current article.
Beware: You need to change the Rprofile.site file on each VM separately.

Option 1: Change the Rprofile.site file manually

  1. Connect to the VM
  2. Inside the VM, search for Wordpad > Right-click > Click on Run as administrator
  3. In Wordpad, click on File > Open 
  4. Browse to C:\Program Files\R\R-[Version]\etc
  5. Select Rprofile.site and click on Open
  6. On the bottom of the file, add the following line (without a '#'):
  7. options(repos = c(CRAN_mirror = "http://cran.r-project.org"))
  8. Click on Save and then on Close.

Option 2: Replace the existing Rprofile.site file

  1. Download the attached Rprofile.site file (see bottom of the current article)
  2. Upload the file to your workspace
  3. Connect to the VM
  4. Inside the VM, open file explorer
  5. Find your uploaded Rprofile.site file > Right-click > Click on Copy
  6. Browse to to C:\Program Files\R\R-[Version]\etc
  7. In this folder, right-click > Click on Paste
  8. Approve that the file is overwritten

You should now be able to install CRAN packages

If you carefully followed the instructions above, you should be able to install packages in R. We strongly advise to install packages in ADMIN mode (right click R or RStudio, run as admin), as this ensures the installed packages are available for any user accessing the Windows VM.
  1. Find Rstudio in the startmenu, right -click > More > click on Run as administrator;
  2. Install the required packages with:
install.packages(<packages>)
If you find that you're still experiencing problems with installing packages, you can also include the line from Step 2 in your code:
options(repos = c(CRAN_mirror = "http://cran.r-project.org"))
Still not working? Add a ticket and ask for assistance of the Core Support Team.

Making Bioconductor packages available in your workspace

Beware: Until the instructions in this section have been followed, Bioconductor packages are not available. 
Only Owners can make packages available for the workspace
Apart from CRAN packages, you may also want to use Bioconductor packages. Just like for CRAN packages, Owners need to (1) create and enable some External Access rules and (2) adjust the Rprofile.site file. Additionally, they need to (3) add a config.yaml file.
The instructions below require you to make use of the most recent Bioconductor (v3.15), which only works with R v4.2.0. Refer to the How do I install R and RStudio? to learn how to (manually) install this version if it's not yet available.

Step 1: Create and activate External Access rules

Just like for the CRAN repo, add two rules for a Bioconductor repo. For instructions, refer to step 1 of the CRAN section above.
RuleIP addressPortReason
Bioconductor443129.217.206.11443Access to bioconductor.org via http://bioconductor.statistik.tu-dortmund.de
Bioconductor80129.217.206.1180Access to bioconductor.org via http://bioconductor.statistik.tu-dortmund.de

Step 2: Change the Rprofile.site file of your R installation

You need to add a couple of lines to the Rprofile.site file:
options(BIOCONDUCTOR_ONLINE_VERSION_DIAGNOSIS = FALSE)
options(BIOCONDUCTOR_CONFIG_FILE = "C:/Program Files/R/R-4.2.0/etc/config.yaml")
You can choose to add them by yourself manually, or to use the Rprofile.site file attached to the article (which includes both the CRAN line and these lines). For instructions, refer to step 2 of the CRAN section.

Step 3: Add config.yaml file

Lastly, you need to add a config.yaml file which is specific to Bioconductor versions. 
  1. Download the attached config.yaml file (suitable for version R v4.2 and Bioconductor v3.15)
  2. Upload it to your DRE workspace
  3. Connect to a VM in the workspace
  4. Inside the VM, open file explorer
  5. Find your uploaded config.yaml file > Right-click > Click on Copy
  6. Browse to to C:\Program Files\R\R-4.2.0\etc
  7. In this folder, right-click > Click on Paste

You should now be able to install Bioconductor packages

We recommend to use install.packages() to install Bioconductor packages. We also strongly advise to install packages in ADMIN mode (right click R or RStudio, run as admin), as this ensures the installed packages are available for any user accessing the Windows VM. For instructions, see the corresponding paragraph in the CRAN section.

How do I install R and RStudio?

These steps you perform on your own desktop. 
There might be a software share available.
You can install R and RStudio by yourself or via available application managers/software stores, depending on the template of your VM.
[volgorde van installaties neerzetten]

Install via application manager/software store

If there's an app manager or software store on your VM, R and RStudio are likely included. For instructions on how to use the managers/stores, refer to the institution-specific articles:
  1. Application manager Radboudumc (only accesible when logged into myDRE support)
  2. Software store UMC Utrecht  (only accesible when logged into myDRE support)

Self-service installation

The benefit of installing in this way is that you have full control over which versions you use. 
  1. Download R and the corresponding version of Rtools: https://cran.r-project.org/bin/windows/
    1. Tip: You can directly download R and Rtools via this link within the VM, if the external access rules as described above have been added and enabled.
  2. (if not following the tip) Upload the .exe files to your workspace by drag and dropping them in the Files tab.
  3. Connect to the VM.
  4. On the VM, right-click on the executables > Run as administrator. 
  5. Follow the installations steps. 

    • Related Articles

    • External access in your workspace

      Introduction By default myDRE workspaces do not have connection to the internet. This ensures that data within the workspace is secure and auditable - we know what comes in, and what goes out. However, sometimes you do need a connection to a web ...
    • R/RStudio installation using domain allowlisting on Windows VMs

      First version: 2022-08-22 Last version: 2023-12-15 Last change: Added an alternative for installing packages from Github (installation from manually downloaded repository). This is a community effort. The article was created by the anDREa Support ...
    • Castor R-Package

      Prerequisites DRE: Owner access to workspace, to install R / RStudio / Rtools in a virtual machine External access to CRAN in the workspace where you want to export the data to (open up port rule) External access to Castor in the workspace where you ...
    • Installing R and Bioconductor packages

      Recently some users experienced issues with accessing R-packages and Bioconductor-packages. The article R and RStudio has been rewritten in order to easily install R and Bioconductor-packages in your Workspace.
    • Using Castor in Python

      Introduction anDREa would like to thank Reinier van Linschoten for bringing this package and description to our attention. This is a Python package for interacting with the API of Castor Electronic Data Capture (EDC). The package contains functions ...