3.4. R packages#
If your software of interest is available as an R
package on CRAN or Bioconductor,
you can install it using the install.packages()
or BiocManager::install()
commands respectively.
Note
Your software might already be available using The quick and easy method.
Search for package names starting with
r-cran-
or r-bioc-
.
3.4.1. Requirements#
The r-base package installed#
The r-base
package provides the GNU
R statistical computation and graphics system.
If you do not have it installed, follow
The quick and easy method, and search and install
the r-base
package.
Attention
You should not add sudo in the commands below.
This method only installs files in your home directory and so does not require administrator privileges.
3.4.2. Starting an R session#
To start an R session, open a terminal window.
Type the R
command and press the ENTER key.
user@cookbook:~$ R
You will be placed inside an R session. Some additional information will be displayed, including the version of R installed.
You can type R commands at the >
prompt.
R version 3.6.3 (2020-02-29) -- "Holding the Windsock"
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.
>
3.4.3. Installing a package from CRAN#
You can search for R packages on CRAN by consulting the Task Views for a categorized listing or the Table of available packages (currently 17157 packages). Once you have identified a package to install, you can follow the steps below to install it.
I will install the BiocManager package as an example below.
1. Install package using install.packages()
command#
At the prompt, type the install.packages()
command
with the name of the package in quotes. For example:
install.packages("BiocManager")
Press the ENTER key to proceed.
2. Confirm use of personal library#
You will notice a prompt requesting you to confirm if you would like to use a personal library:
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
Warning in install.packages("BiocManager") :
'lib = "/usr/local/lib/R/site-library"' is not writable
Would you like to use a personal library instead? (yes/No/cancel) yes
Type yes
to confirm and press the ENTER key.
Why use a personal library?.
3. Create personal library if necessary#
If you have never installed a package, the personal library directory will not exist. If so, you will be prompted for confirmation to create it:
Would you like to create a personal library
‘~/R/x86_64-pc-linux-gnu-library/3.6’
to install packages into? (yes/No/cancel) yes
Type yes
to confirm and press the ENTER
key.
Note
The next time you install a package, you will not see this prompt.
4. Package installation summary#
Installation should now proceed:
trying URL 'https://cloud.r-project.org/src/contrib/BiocManager_1.30.10.tar.gz'
Content type 'application/x-gzip' length 40205 bytes (39 KB)
==================================================
downloaded 39 KB
* installing *source* package ‘BiocManager’ ...
** package ‘BiocManager’ successfully unpacked and MD5 sums checked
** using staged installation
** 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
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (BiocManager)
The downloaded source packages are in
‘/tmp/RtmpDgmOZ8/downloaded_packages’
>
If there are no errors during the process, the package installation is successful.
3.4.4. Installing a package from Bioconductor#
You can search the Bioconductor software package list on the website (currently has 1974 packages). Once you have identified a package to install, you can follow the steps below to install it.
I will install the edgeR package as an example.
Install package using BiocManager::install()
command#
Install the BiocManager package. This is necessary for installing R packages from Bioconductor repository.
Note
You only need to do this once.
The next time you wish to install a package from Bioconductor, you can proceed to step 3.
At the R prompt, use the
BiocManager::install()
command with the name of the package you would like to install in quotes.For example:
BiocManager::install("edgeR")
Press the ENTER key to proceed.
The package and its dependencies will now be downloaded, compiled and installed.
Output:
Bioconductor version 3.10 (BiocManager 1.30.10), R 3.6.3 (2020-02-29) Installing package(s) 'BiocVersion', 'edgeR' also installing the dependencies ‘limma’, ‘locfit’, ‘Rcpp’ ... ** 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 (edgeR)
If there are no errors during the process, the package installation is successful.
3.4.5. Updating a package#
When an update is available for a package, use the following commands to update.
For packages installed from CRAN:
install.packages("BiocManager")
For packages installed from Bioconductor:
BiocManager::install("edgeR")
3.4.6. Removing a package#
To remove an installed package, use the
remove.packages()
command with the name of the package
in quotes.
For example:
remove.packages("BiocManager")
3.4.7. Notes#
The r-base-dev and build-essential packages#
If you are installing additional packages from CRAN and
other sources, you will also need to install the
r-base-dev
and build-essential
packages.
However, when you install r-base
, these packages
will also be installed as dependencies so, you do not
have to install them manually.
Why use a personal library?#
When installing packages, R will first attempt to use a
system library — for example, /usr/local/lib/R/site-library
.
This path can only be modified by a user
with administrator privileges. This is why a personal
library in the $HOME
directory is a better option for
users to install packages.
Comments