How to Install Old Version R Packages in R
Why Install Old Version Packages
After upgrading R, one of the most common problems is that older packages have not yet caught up with the new release. The usual symptom is a package manager error telling you that the package is not available for your current R version.
This article records the most practical workaround: download the source package yourself and install it with R CMD INSTALL. It is a manual path, but on servers it is often the most reliable one.
To leverage the efficiency improvements and bug fixes of R version updates, I upgraded R on my server to the latest version (currently 4.1). However, when using some packages, I encountered errors like:
Warning message:
“package ‘clusterProfiler’ is not available for this version of R
or
Warning message:
“package ‘EnrichmentBrowser’ is not available for this version of R
Warning message:
“package ‘qvalue’ is not available for this version of R
These errors occur because clusterProfiler, EnrichmentBrowser, or qvalue have not kept pace with R’s updates. If you need to use them on a newer version, you must use special installation methods.
What to check before installing
Before manually installing a source package, verify three things first:
- Your current R version
- The source package version you plan to use
- Whether the system has a working build toolchain
Useful checks:
R --version
R CMD config CC
R CMD config CXX
If the server does not have a basic compiler toolchain, source installation usually fails halfway through.
Install from Source
Most of the time, this is the most stable method. Although direct installation via R commands isn’t possible, you can install by downloading the source code. For example, qvalue:
- First, download the installation package.
Find the download link for the
qvalueinstallation package on bioconductor at qvalue and download it:wget https://bioconductor.org/packages/release/bioc/src/contrib/qvalue_2.26.0.tar.gz - Install
Call R’s installation command directly in the shell:
If the tarball is already on disk and you prefer to stay inside an R session, this is the equivalent source-install form:
R CMD INSTALL qvalue_2.26.0.tar.gzIf successful, you’ll see a correct installation prompt:install.packages("qvalue_2.26.0.tar.gz", repos = NULL, type = "source")* installing to library ‘/home/teng/R/x86_64-pc-linux-gnu-library/4.1’ * installing *source* package ‘qvalue’ ... ** using staged installation ** R ** data ** 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 (qvalue)qvalueis successfully installed.
Similarly, you can install other dependencies one by one.
Finally, clusterProfiler is installed:
R CMD INSTALL clusterProfiler_4.2.2.tar.gz
* installing to library ‘/home/teng/R/x86_64-pc-linux-gnu-library/4.1’
* installing *source* package ‘clusterProfiler’ ...
** using staged installation
** R
** data
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing 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 (clusterProfiler)
If a dependency is missing, install the dependency source packages first and then return to the target package.
How to verify the installation
Do not stop at the DONE line. It is better to load the package and inspect the active session:
R
library(qvalue)
library(clusterProfiler)
sessionInfo()
If library() loads successfully, the package is usually installed correctly in the current R environment.
Common issues
1. Installation fails because the compiler or system libraries are missing
This is the most common source-install failure. The package tarball downloads correctly, but compilation fails because gcc, g++, make, or a required system development library is missing.
2. The target package fails because a dependency was not installed
For packages like clusterProfiler, the real problem is often a dependency rather than the target package itself. The most reliable approach is to install dependencies one by one in the order shown by the error messages.
3. The package was installed, but R still cannot find it
Different R versions often use different library paths. Check the active library search path with:
R -q -e '.libPaths()'
This helps avoid the common mistake of installing into one R library path and loading from another.
Related reading
Summary
This article describes how to install various packages on the latest version of R. Unlike Python, R’s installation method requires many dependencies for the latest version. This time, I downloaded dozens of source codes and installed them one by one. If you don’t want to go through this hassle, it’s better to stick with older R versions. R 3.5 and 3.6 are currently the most convenient for installing various packages, and I recommend using them.
- 原文作者:春江暮客
- 原文链接:https://www.bobobk.com/en/326.html
- 版权声明:本作品采用 知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议 进行许可,非商业转载请注明出处(作者,原文链接),商业转载请联系作者获得授权。