Installing R Packages

R provides built-in mechanisms to install additional packages.

On this page

Before you begin

The R module is available on Pawsey systems:

$ module load r/4.3.0

Pawsey systems also preconfigure the shell environment to provide a meaningful location for user-specific package installations (in this case, R will interpret %v as 4.3.0), as seen below. This step is automatically run for you. 

export R_LIBS_USER=/software/projects/<project-id>/<user-name>/setonix/<DATE-TAG>/r/%v

Install a package using install.packages()

R provides a dedicated function to install packages from within the R environment itself. The install.packages() function is typically the easiest way to install a package, as it takes care of downloading and installing the package, as well as any required dependencies.

Let's load the R module and open an interactive R session:

Terminal 1. Set up and launch an R interactive session
$ module load r/4.3.0

$ R

R version 4.3.0 (2023-04-21) -- "Already Tomorrow"
Copyright (C) 2023 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> 

Now let's install a package; in this case we're going with Rcpp, a package to integrate R and C++ via R functions and a (header-only) C++ library:

Terminal 2. Install with R install.packages()
> install.packages('Rcpp')
Warning in install.packages("Rcpp") :
  'lib = "/software/setonix/2024.05/software/linux-sles15-zen3/gcc-12.2.0/r-4.3.0-llieqbuwjngu7buqaftswodfq3wx65dc/rlib/R/library"' is not writable
Would you like to use a personal library instead? (yes/No/cancel) yes
Would you like to create a personal library
‘/software/projects/<YOUR-PROJECT>/<USERNAME>/setonix/<DATE-TAG>/r/4.3’
to install packages into? (yes/No/cancel) yes
--- Please select a CRAN mirror for use in this session ---

Selection: 2
trying URL 'https://cran.csiro.au/src/contrib/Rcpp_1.0.12.tar.gz'
Content type 'application/x-gzip' length 3430494 bytes (3.3 MB)
==================================================
downloaded 3.3 MB

Failed to query server: Transport endpoint is not connected
Warning in system("timedatectl", intern = TRUE) :
  running command 'timedatectl' had status 1
* installing *source* package ‘Rcpp’ ...
** package ‘Rcpp’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
using C++ compiler: ‘g++ (GCC) 12.2.0 20220819 (HPE)’
CC -std=gnu++17 -I"/software/setonix/2024.05/software/linux-sles15-zen3/gcc-12.2.0/r-4.3.0-llieqbuwjngu7buqaftswodfq3wx65dc/rlib/R/include" -DNDEBUG -I../inst/include/  -I/usr/local/include    -fpic  -g -O2  -c api.cpp -o api.o
CC -std=gnu++17 -I"/software/setonix/2024.05/software/linux-sles15-zen3/gcc-12.2.0/r-4.3.0-llieqbuwjngu7buqaftswodfq3wx65dc/rlib/R/include" -DNDEBUG -I../inst/include/  -I/usr/local/include    -fpic  -g -O2  -c attributes.cpp -o attributes.o
CC -std=gnu++17 -I"/software/setonix/2024.05/software/linux-sles15-zen3/gcc-12.2.0/r-4.3.0-llieqbuwjngu7buqaftswodfq3wx65dc/rlib/R/include" -DNDEBUG -I../inst/include/  -I/usr/local/include    -fpic  -g -O2  -c barrier.cpp -o barrier.o
CC -std=gnu++17 -I"/software/setonix/2024.05/software/linux-sles15-zen3/gcc-12.2.0/r-4.3.0-llieqbuwjngu7buqaftswodfq3wx65dc/rlib/R/include" -DNDEBUG -I../inst/include/  -I/usr/local/include    -fpic  -g -O2  -c date.cpp -o date.o
CC -std=gnu++17 -I"/software/setonix/2024.05/software/linux-sles15-zen3/gcc-12.2.0/r-4.3.0-llieqbuwjngu7buqaftswodfq3wx65dc/rlib/R/include" -DNDEBUG -I../inst/include/  -I/usr/local/include    -fpic  -g -O2  -c module.cpp -o module.o
CC -std=gnu++17 -I"/software/setonix/2024.05/software/linux-sles15-zen3/gcc-12.2.0/r-4.3.0-llieqbuwjngu7buqaftswodfq3wx65dc/rlib/R/include" -DNDEBUG -I../inst/include/  -I/usr/local/include    -fpic  -g -O2  -c rcpp_init.cpp -o rcpp_init.o
CC -std=gnu++17 -shared -L/software/setonix/2024.05/software/linux-sles15-zen3/gcc-12.2.0/r-4.3.0-llieqbuwjngu7buqaftswodfq3wx65dc/rlib/R/lib -L/software/setonix/2024.05/software/linux-sles15-zen3/gcc-12.2.0/r-4.3.0-llieqbuwjngu7buqaftswodfq3wx65dc/rlib/R/lib -Wl,-rpath,/software/setonix/2024.05/software/linux-sles15-zen3/gcc-12.2.0/r-4.3.0-llieqbuwjngu7buqaftswodfq3wx65dc/rlib/R/lib -o Rcpp.so api.o attributes.o barrier.o date.o module.o rcpp_init.o -L/software/setonix/2024.05/software/linux-sles15-zen3/gcc-12.2.0/r-4.3.0-llieqbuwjngu7buqaftswodfq3wx65dc/rlib/R/lib -lR
installing to /software/projects/<YOUR-PROJECT>/<USERNAME>/setonix/<DATE-TAG>/r/4.3/00LOCK-Rcpp/00new/Rcpp/libs
** R
** inst
** byte-compile and prepare package for lazy loading
code for methods in class “C++OverloadedMethods” was not checked for suspicious field assignments (recommended package ‘codetools’ not available?)
code for methods in class “RcppClass” was not checked for suspicious field assignments (recommended package ‘codetools’ not available?)
code for methods in class “RcppClass” was not checked for suspicious field assignments (recommended package ‘codetools’ not available?)
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** checking absolute paths in shared objects and dynamic libraries
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (Rcpp)

The downloaded source packages are in
	‘/tmp/Rtmpt5xEuR/downloaded_packages’
> 


If you want to install this package in a different location to /software/projects/<YOUR-PROJECT>/<USERNAME>/setonix/<DATE-TAG>/r/%v above, you can specify the install location by adding the lib=/install/path/for/package flag, as shown in the example below:

Terminal 3. Specify install location with lib= flag
> install.packages('Rcpp', lib='/software/projects/<YOUR-PROJECT>/manual/r/4.3')
Installing package into ‘/software/projects/<YOUR-PROJECT>/manual/r/4.3’
(as ‘lib’ is unspecified)
trying URL 'https://cran.curtin.edu.au/src/contrib/Rcpp_1.0.6.tar.gz'
Content type 'application/x-gzip' length 2952876 bytes (2.8 MB)
==================================================
downloaded 2.8 MB

* installing *source* package ‘Rcpp’ ...
** package ‘Rcpp’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
g++ -std=gnu++11 -I"/pawsey/sles12sp3/apps/sandybridge/gcc/4.8.5/r/4.3.0/lib64/R/include" -DNDEBUG -I../inst/include/  -I/usr/local/include  -fpic  -g -O2  -c api.cpp -o api.o
g++ -std=gnu++11 -I"/pawsey/sles12sp3/apps/sandybridge/gcc/4.8.5/r/4.3.0/lib64/R/include" -DNDEBUG -I../inst/include/  -I/usr/local/include  -fpic  -g -O2  -c attributes.cpp -o attributes.o
g++ -std=gnu++11 -I"/pawsey/sles12sp3/apps/sandybridge/gcc/4.8.5/r/4.3.0/lib64/R/include" -DNDEBUG -I../inst/include/  -I/usr/local/include  -fpic  -g -O2  -c barrier.cpp -o barrier.o
g++ -std=gnu++11 -I"/pawsey/sles12sp3/apps/sandybridge/gcc/4.8.5/r/4.3.0/lib64/R/include" -DNDEBUG -I../inst/include/  -I/usr/local/include  -fpic  -g -O2  -c date.cpp -o date.o
g++ -std=gnu++11 -I"/pawsey/sles12sp3/apps/sandybridge/gcc/4.8.5/r/4.3.0/lib64/R/include" -DNDEBUG -I../inst/include/  -I/usr/local/include  -fpic  -g -O2  -c module.cpp -o module.o
g++ -std=gnu++11 -I"/pawsey/sles12sp3/apps/sandybridge/gcc/4.8.5/r/4.3.0/lib64/R/include" -DNDEBUG -I../inst/include/  -I/usr/local/include  -fpic  -g -O2  -c rcpp_init.cpp -o rcpp_init.o
g++ -std=gnu++11 -shared -L/pawsey/sles12sp3/apps/sandybridge/gcc/4.8.5/r/4.3.0/lib64/R/lib -L/usr/local/lib64 -o Rcpp.so api.o attributes.o barrier.o date.o module.o rcpp_init.o -L/pawsey/sles12sp3/apps/sandybridge/gcc/4.8.5/r/4.3.0/lib64/R/lib -lR
installing to /software/projects/<YOUR-PROJECT>/manual/r/4.3/00LOCK-Rcpp/00new/Rcpp/libs
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** checking absolute paths in shared objects and dynamic libraries
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (Rcpp)

The downloaded source packages are in
	‘/tmp/Rtmp39wZil/downloaded_packages’
> 

Install a package using R CMD INSTALL

R also provides a Linux shell option to install packages, via the command R CMD INSTALL. This command requires the package tarball to be already downloaded. It will not take care of any dependencies, so it is an effective method only for simple installations.

Let's load the R module:

$ module load r/4.3.0

Now let's install Rcpp from its downloaded tarball:

Terminal 3. Install with R CMD INSTALL
$ R CMD INSTALL Rcpp_1.0.6.tar.gz 
* installing to library ‘/software/projects/<YOUR-PROJECT>/<USERNAME>/setonix/<DATE-TAG>/r/4.3’
* installing *source* package ‘Rcpp’ ...
** package ‘Rcpp’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
g++ -std=gnu++11 -I"/pawsey/sles12sp3/apps/sandybridge/gcc/4.8.5/r/4.3.0/lib64/R/include" -DNDEBUG -I../inst/include/  -I/usr/local/include  -fpic  -g -O2  -c api.cpp -o api.o
g++ -std=gnu++11 -I"/pawsey/sles12sp3/apps/sandybridge/gcc/4.8.5/r/4.3.0/lib64/R/include" -DNDEBUG -I../inst/include/  -I/usr/local/include  -fpic  -g -O2  -c attributes.cpp -o attributes.o
g++ -std=gnu++11 -I"/pawsey/sles12sp3/apps/sandybridge/gcc/4.8.5/r/4.3.0/lib64/R/include" -DNDEBUG -I../inst/include/  -I/usr/local/include  -fpic  -g -O2  -c barrier.cpp -o barrier.o
g++ -std=gnu++11 -I"/pawsey/sles12sp3/apps/sandybridge/gcc/4.8.5/r/4.3.0/lib64/R/include" -DNDEBUG -I../inst/include/  -I/usr/local/include  -fpic  -g -O2  -c date.cpp -o date.o
g++ -std=gnu++11 -I"/pawsey/sles12sp3/apps/sandybridge/gcc/4.8.5/r/4.3.0/lib64/R/include" -DNDEBUG -I../inst/include/  -I/usr/local/include  -fpic  -g -O2  -c module.cpp -o module.o
g++ -std=gnu++11 -I"/pawsey/sles12sp3/apps/sandybridge/gcc/4.8.5/r/4.3.0/lib64/R/include" -DNDEBUG -I../inst/include/  -I/usr/local/include  -fpic  -g -O2  -c rcpp_init.cpp -o rcpp_init.o
g++ -std=gnu++11 -shared -L/pawsey/sles12sp3/apps/sandybridge/gcc/4.8.5/r/4.3.0/lib64/R/lib -L/usr/local/lib64 -o Rcpp.so api.o attributes.o barrier.o date.o module.o rcpp_init.o -L/pawsey/sles12sp3/apps/sandybridge/gcc/4.8.5/r/4.3.0/lib64/R/lib -lR
installing to /software/projects/<YOUR-PROJECT>/<USERNAME>/setonix/<DATE-TAG>/r/4.3/00LOCK-Rcpp/00new/Rcpp/libs
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** checking absolute paths in shared objects and dynamic libraries
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (Rcpp)


An alternative way to install from a tarball is to use the install.packages("Rcpp_1.0.6.tar.gz"). This assumes the tarball is in your working directory. It is also possible to additionally specify the installation location by adding the  lib=/install/path/for/package flag.

Let's load the R module:


$ module load r/4.3.0


Now let's install Rcpp from its downloaded tarball and specify the install location:

Terminal 5. Install from tarball with install.packages()
> install.packages('Rcpp_1.0.6.tar.gz', lib='/software/projects/<project-id>/manual/r/4.3')
Installing package into ‘/software/projects/<project-id>/manual/r/4.3’
(as ‘lib’ is unspecified)
trying URL 'https://cran.curtin.edu.au/src/contrib/Rcpp_1.0.6.tar.gz'
Content type 'application/x-gzip' length 2952876 bytes (2.8 MB)
==================================================
downloaded 2.8 MB

* installing *source* package ‘Rcpp’ ...
** package ‘Rcpp’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
g++ -std=gnu++11 -I"/pawsey/sles12sp3/apps/sandybridge/gcc/4.8.5/r/4.3.0/lib64/R/include" -DNDEBUG -I../inst/include/  -I/usr/local/include  -fpic  -g -O2  -c api.cpp -o api.o
g++ -std=gnu++11 -I"/pawsey/sles12sp3/apps/sandybridge/gcc/4.8.5/r/4.3.0/lib64/R/include" -DNDEBUG -I../inst/include/  -I/usr/local/include  -fpic  -g -O2  -c attributes.cpp -o attributes.o
g++ -std=gnu++11 -I"/pawsey/sles12sp3/apps/sandybridge/gcc/4.8.5/r/4.3.0/lib64/R/include" -DNDEBUG -I../inst/include/  -I/usr/local/include  -fpic  -g -O2  -c barrier.cpp -o barrier.o
g++ -std=gnu++11 -I"/pawsey/sles12sp3/apps/sandybridge/gcc/4.8.5/r/4.3.0/lib64/R/include" -DNDEBUG -I../inst/include/  -I/usr/local/include  -fpic  -g -O2  -c date.cpp -o date.o
g++ -std=gnu++11 -I"/pawsey/sles12sp3/apps/sandybridge/gcc/4.8.5/r/4.3.0/lib64/R/include" -DNDEBUG -I../inst/include/  -I/usr/local/include  -fpic  -g -O2  -c module.cpp -o module.o
g++ -std=gnu++11 -I"/pawsey/sles12sp3/apps/sandybridge/gcc/4.8.5/r/4.3.0/lib64/R/include" -DNDEBUG -I../inst/include/  -I/usr/local/include  -fpic  -g -O2  -c rcpp_init.cpp -o rcpp_init.o
g++ -std=gnu++11 -shared -L/pawsey/sles12sp3/apps/sandybridge/gcc/4.8.5/r/4.3.0/lib64/R/lib -L/usr/local/lib64 -o Rcpp.so api.o attributes.o barrier.o date.o module.o rcpp_init.o -L/pawsey/sles12sp3/apps/sandybridge/gcc/4.8.5/r/4.3.0/lib64/R/lib -lR
installing to /software/projects/<project-id>/manual/r/4.3/00LOCK-Rcpp/00new/Rcpp/libs
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** checking absolute paths in shared objects and dynamic libraries
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (Rcpp)

The downloaded source packages are in
	‘/tmp/Rtmp39wZil/downloaded_packages’
> 

Related pages

External links