Install Additional R Packages
We have included common data libraries for R. The R environment on the platform does not have access to CRAN or a CRAN mirror. This means you will not be able to install the R packages directly as you may be accustomed to. The easiest work around is to use miniCRAN. For more documentation, refer to the documentation -- https://andrie.github.io/miniCRAN/.
In order to do this process, you will need internet access and R installed locally. The process involves creating a local miniCRAN repo, which will be uploaded to the platform.
Create local miniCRAN repo
First, open a R interpreter on your local computer and install miniCRAN.
install.packages("miniCRAN")
library("miniCRAN")
Create a directory that will be your miniCRAN repository. Make sure you pick a file path that you will be able to locate.
dir.create(pth <- file.path(“.”, “miniCRAN”))
Identify which packages you need and create a list. Do not worry about dependencies; those will be identified and included when the repo is created. Note: ggplot2 is already on the platform. This is just an example.
pkgs <- c(“ggplot2”)
Create a local repository with chosen packages and dependencies. After executing this next line, you may be prompted to pick a CRAN server. Pick whichever one that works best for you. They are organized by region.
makeRepo(pkgDep(pkgs), path = pth, Rversion=4.1)
You can now close R.
Uploading Repo
Navigate to your local miniCRAN repo. You will need to archive the directory so that it can easily be uploaded to the platform. Here is an example:
Next, you will need to start an instance on the platform. Use the file browser to navigate to the location you would like to upload this repo. Then hit the upload button.
After uploading the ZIP file. Use a terminal to extract the repo.
Add Library Path
The default directory that contains the installed R packages will not be writable on the platform. You will need to create and set a user directory. Do this by executing the following lines in a terminal tab on the platform. Just change the path.
mkdir -p ~/path/to/lib
echo R_LIBS_USER=~/path/to/lib > ~/.Renviron
When R launches it will add the R_LIBS_USER
environment variable from .Rversion
to the list of paths it uses to find packages.
If the library directory is in the ~/project
directory, other project members can use it. They will just need to added the R_LIBS_USER
environment variable.
Install Packages
Next you can install the packages. Open a R interpreter or R notebook and execute the lines below. You will need to specify the path to the extracted miniCRAN repo directory. This should only needed to be done once.
install.packages("ggplot2", repos="file:///home/ngsci/R-repos/miniCRAN/")
After this the packages are ready to use. Note: ggplot2 is already on the platform.
library(ggplot2)