Architect for Command Line R

If you want to use R in a terminal and use the exact same version as the one shipped with Architect, there are two ways that are supported on GNU/Linux:

  • use the update-alternatives mechanism (recommended)
  • define a simple alias in your bash configuration file .bashrc.

Use update-alternatives

The update-alternatives mechanism is a generic mechanism offered on Linux to switch between similar programs e.g. different versions of R. Since Architect ships with R, you can configure your system to use this version of R instead of other R versions installed on your system.

For a fully automated way of doing this, please see the dedicated section using a script. For a manual approach, please execute the steps described below.

Manual

  • If defined, remove the R alias from the .bashrc script in your home directory (mentioned under ‘Define an alias’).
  • Check whether R has been defined in update-alternatives:
sudo update-alternatives --list R

If not defined, the following message will appear:

update-alternatives: error: no alternatives for R

If defined, a list with R alternatives will be printed.

  • Create a script in /usr/local/bin called R-architect.sh (or any other name or path of your choosing) with the following contents:
#!/usr/bin/env bash
R_LIBS_SITE=/opt/architect/plugins/eu.openanalytics.architect.r.libs.rj.gtk.linux/libs R_LIBS_USER=~/.architect/workspace/.metadata/.r/eplugin-local-eu.openanalytics.r.server/user-library /opt/architect/plugins/eu.openanalytics.architect.r.server.gtk.linux/R/bin/R "$@"
  • Make sure the script is executable:
sudo chmod +x /usr/local/bin/R-architect.sh

Launch the script and verify that it uses the right library paths inside the R session:

/usr/local/bin/R-architect.sh
> .libPaths()
[1] "/home/tverbeke/.architect/workspace/.metadata/.r/eplugin-local-eu.openanalytics.r.server/user-library"   
[2] "/opt/architect/plugins/eu.openanalytics.architect.r.libs.rj.gtk.linux.x86_64_1.3.0.202402232217/libs"    
[3] "/opt/architect/plugins/eu.openanalytics.architect.r.server.gtk.linux.x86_64_1.3.0.202402232217/R/library"

Note: in the .libPaths() you will see paths with specific version numbers (e.g. 1.3.0.202402232217) whereas the R-architect.sh script includes paths without these version numbers. The reason is that Architect defines symbolic links that you can use to always point to the right directories, also when you upgrade Architect versions.

All R packages will by default be installed in the Architect workspace and will also be accessible from the R console in this way.

R has not been defined in update-alternatives

  • If installed (i.e. via r-base from the CRAN repository), remove the R binary in /usr/bin/R
sudo rm /usr/bin/R
  • Install your Architect R in update-alternatives using the following command:
sudo update-alternatives --install /usr/bin/R R /usr/local/bin/R-architect.sh 100
  • (optional) Install any other R (i.e. from the CRAN repository) in update-alternatives:
sudo update-alternatives --install /usr/bin/R R /usr/lib/R/bin/R 80

where /usr/lib/R/bin/R is the location of the other R binary.

R has been defined in update-alternatives

  • If you want to add your Architect R and it’s not in the list that the first update-alternatives command printed out, use the following command:
sudo update-alternatives --install /usr/bin/R R /usr/local/bin/R-architect.sh 100
  • (optional) Install any other R (i.e. from the CRAN repository) in update-alternatives:
sudo update-alternatives --install /usr/bin/R R /usr/lib/R/bin/R 80

Where /usr/lib/R/bin/R is the location of the other R binary.

change the default R

If you want to change which R will be used by default:

sudo update-alternatives --config R

And select (using a number) which R should be configured as the default R.

Using a Script

The steps detailed above that describe the manual procedure are also available under the form of a script you can use to automate the procedure. In order to run the procedure:

sudo bash ~/Downloads/configure-R-alternatives

The script should be compatible with both older and newer versions of Architect. It will configure the Architect version for both the R and Rscript executables.

Define an Alias

A simpler but less flexible method to make use of the R from Architect at the command line is to specify an alias. When you specify such an alias you need to include a number of environment variables (R_LIBS_SITE and R_LIBS_USER) to make sure that the Architect R libraries are put on the library path of your R session:

alias R='R_LIBS_SITE=/opt/architect/plugins/eu.openanalytics.architect.r.libs.rj.gtk.linux/libs R_LIBS_USER=~/.architect/workspace/.metadata/.r/eplugin-local-eu.openanalytics.r.server/user-library /opt/architect/plugins/eu.openanalytics.architect.r.server.gtk.linux/R/bin/R'

If you have set the alias correctly, you should see something along the following for the .libPaths():

> .libPaths()
[1] "/home/tverbeke/.architect/workspace/.metadata/.r/eplugin-local-eu.openanalytics.r.server/user-library"   
[2] "/opt/architect/plugins/eu.openanalytics.architect.r.libs.rj.gtk.linux.x86_64_1.3.0.202402232217/libs"    
[3] "/opt/architect/plugins/eu.openanalytics.architect.r.server.gtk.linux.x86_64_1.3.0.202402232217/R/library"

It is also possible to directly define the alias from an R session running inside Architect. To achieve this, run the following code in your Architect R session:

aliasCmd <- paste0("alias R='R_LIBS_SITE=",.Library.site," R_LIBS_USER=",.libPaths()[1]," ",Sys.which("R"),"'")
cat(aliasCmd, file = "~/.bashrc", append = TRUE)

Note: in the .libPaths() you will see paths with specific version numbers (e.g. 1.3.0.202402232217) whereas the alias includes paths without these version numbers. The reason is that Architect defines symbolic links that you can use in your alias to always point to the right directories, also when you upgrade Architect versions.