Chapter 10 Install & Update R Packages
10.1 Introduction
In this chapter, we will learn about R packages. Packages are fundamental to R. There are more than 22,000 packages available on CRAN or the Comprehensive R Archive Network (as of September 2026; verify the current count at cran.r-project.org/web/packages).
Packages are available for different topics. You should always look for a package before writing code from scratch. In case you have written your own codes for a new analysis or topic, do share it with the R community by converting the code into a package. You can learn more about building R packages from R Packages, a book written by Hadley Wickham.
In this chapter, we will learn to:
- install R packages from
- CRAN
- GitHub
- BitBucket
- Bioconductor
- rForge
- install different versions of a package
- load, update & remove installed packages
- access package documentation
10.2 Install Packages
10.2.1 CRAN
Packages from CRAN can be installed using install.packages(). The name of the package must be enclosed in single or double quotes.
10.2.2 GitHub
Some R packages are made available on GitHub before releasing them on CRAN. Such packages can be installed using install_github() from devtools or remotes package. You need to specify the name of the repository and the package. For example, to download ggplot2 or dplyr, below is the code:
10.2.3 BitBucket
Bitbucket is similar to GitHub. You can install packages from Bitbucket using install_bitbucket() from devtools or remotes package.
10.2.4 Bioconductor
Bioconductor provides tools for analysis and comprehension of high throughput genomic data. Install the BiocManager package and use BiocManager::install():
10.2.5 rForge
Many R packages are hosted at R-Forge, a platform for development of R packages. (Note: R-Forge is largely inactive today; prefer CRAN or GitHub for new work.)
For faster installs with dependency resolution, you can also try
pak::pkg_install()from the pak package as a modern alternative.
10.3 Install Different Versions
Now that we have learnt how to install packages, let us look at installing different versions of the same package.
If you want to install the latest release from GitHub, append @*release to the repository name. For example, to install the latest release of dplyr:
10.4 Installed Packages
installed.packages(): view currently installed packageslibrary('package_name'): load packagesautoload('function_name', 'package_name'): load functions and data from packages only when called in the scriptavailable.packages(): packages available for installationold.packages(): packages which have new versions availablenew.packages(): packages already not installedupdate.packages(): update packages which have new versionsremove.packages('package_name'): remove installed packages
10.5 Library Paths
Library is a directory that contains all installed packages. Usually there will be more than one R library in your system. You can find the location of the libraries using .libPaths().
## [1] "C:/Users/HP/AppData/Local/R/cache/R/renv/library/intro-r-15ca35ae/windows/R-4.5/x86_64-w64-mingw32"
## [2] "C:/Users/HP/AppData/Local/R/cache/R/renv/sandbox/windows/R-4.5/x86_64-w64-mingw32/ebc25411"
You can use lib when you want to install, load, update and remove packages from a particular library.
10.5.4 Remove Packages
Explore Rsquared Academy’s own R packages and guides at pkgs.rsquaredacademy.com.