Skip to end of banner
Go to start of banner

Installing R Packages

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »

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.2.2

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.1), as seen below. This step is automatically run for you. 

export R_LIBS_USER=/software/projects/<project-id>/<user-name>/setonix/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.1.0

$ R

R version 4.1.0 (2021-05-18) -- "Camp Pontanezen"
Copyright (C) 2020 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')
Installing package into ‘/software/projects/<project-id>/<user-name>/r/3.6’
(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/3.6.3/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/3.6.3/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/3.6.3/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/3.6.3/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/3.6.3/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/3.6.3/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/3.6.3/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/3.6.3/lib64/R/lib -lR
installing to /software/projects/<project-id>/<user-name>/r/3.6/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’
> 


If you want to install this package in a different location to /software/projects/<project-id>/<user-name>/setonix/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/<project-id>/<user-name>/r/3.6')
Installing package into ‘/software/projects/<project-id>/<user-name>/r/3.6’
(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/3.6.3/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/3.6.3/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/3.6.3/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/3.6.3/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/3.6.3/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/3.6.3/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/3.6.3/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/3.6.3/lib64/R/lib -lR
installing to /group/diff_projcode/rsrchr/software/r/3.6/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.2.2

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/<project-id>/<user-name>/r/3.6’
* 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/3.6.3/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/3.6.3/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/3.6.3/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/3.6.3/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/3.6.3/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/3.6.3/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/3.6.3/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/3.6.3/lib64/R/lib -lR
installing to /group/projcode/rsrchr/software/r/3.6/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.2.2


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>/<user-name>/r/3.6')
Installing package into ‘/software/projects/<project-id>/<user-name>/r/3.6’
(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/3.6.3/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/3.6.3/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/3.6.3/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/3.6.3/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/3.6.3/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/3.6.3/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/3.6.3/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/3.6.3/lib64/R/lib -lR
installing to /group/diff_projcode/rsrchr/software/r/3.6/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

  • No labels