Global Settings

This chapter covers global system settings that will be applied to all users.

tmp folder

By default Ubuntu uses “/tmp” folder for temporary storage. In our current setup we use rather small internal ec-2 storage. So there’s a certain risk that this storage will be filled to capacity, especially if somebody happens to be doing Stan modeling. Therefore it makes sense to set the default temporary storage to a folder on the mounted persistent drive.

First let’s create this folder and set access permissions appropriately:

sudo mkdir /pfs/tmp
sudo chmod 1777 /pfs/tmp

Here 777 means that we give all permissions for all users and 1 at the beginning means the sticky-bit flag. This flag ensures that any new file or folder created in tmp will only be editable by the user who created it. This is a typical setting for tmp directories. See more details in Wikipedia.

To make R use this folder, we need to setup TMPDIR global environment variable. One way to do it is to set this up in /etc/rstudio/rsession-profile script.

# /etc/rstudio/rsession-profile
export TMPDIR=/pfs/tmp

We also have to make this file executable for all users.

sudo chmod 755 /etc/rstudio/rsession-profile

Rprofile.site

In case if we want an R script to be executed at the start of all sessions, we need to set up Rprofile.site file. By default R looks into “etc” subfolder of R installation folder. So this way we’d need to set Rprofile.site for each R version individually. But as long as we don’t have any version-specific settings, it makes more sense to have one global Rprofile.site. This will be easier to maintain. Let’s create one at /pfs/global/Rprofile.site, it is sufficient if only reading right is provided for all. To point R to it, we need to set up global environment variable called R_PROFILE:

# /etc/rstudio/rsession-profile
export R_PROFILE=/pfs/global/Rprofile.site

As for the contents of this file, I’ve initialized it with the following code:

local({
  if (Sys.getenv("GH_PAT") != "") {
    creds <- list(
      protocol = "https",
      host = "github.com",
      username = "personalAccessToken",
      password = Sys.getenv("GH_PAT")
    )
    creds_file <- tempfile()
    writeLines(paste(names(creds), creds, sep = "="), creds_file)
    system2("git", "credential approve", stdin = creds_file, stdout = TRUE)
    file.remove(creds_file)
  }
  return(invisible())
})

This searches for GH_PAT environment variable and, if it’s not empty, sets up GitHub PAT in the credential helper. This way RStudio will automatically use the PAT without asking any additional questions. Note that if GITHUB_PAT variable is set up, it may prevent RStudio from getting PAT from credential helper.