R语言---Ubuntu中R语言更新至R4.2
时间: 2022-10-23
1. Ubuntu18.04升级R语言至R4.2
进入R官网(https://cloud.r-project.org/)进入ubuntu下载页面,或者直接搜索Ubuntu Packages For R - Brief Instructions
进入。
(1)更新下载地址
# update indices
sudo apt update -qq
# install two helper packages we need
sudo apt install --no-install-recommends software-properties-common dirmngr
# add the signing key (by Michael Rutter) for these repos
# To verify key, run gpg --show-keys /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc
# Fingerprint: E298A3A825C0D65DFD57CBB651716619E084DAB9
wget -qO- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | \
sudo tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc
# add the R 4.0 repo from CRAN -- adjust 'focal' to 'groovy' or 'bionic' as needed
sudo add-apt-repository "deb https://cloud.r-project.org/bin/linux/ubuntu $(lsb_release -cs)-cran40/"
(2)sudo下载
下载最新版本R语言
sudo apt install --no-install-recommends r-base
使用上面的参数只下载必要的依赖文件:
详细版本的R更新可以查看:
https://cloud.r-project.org/bin/linux/ubuntu/fullREADME.html
2. 重新下载R包
(1)只更新Bioconductor包
以ComplexHeatmap
为例:
https://www.bioconductor.org/packages/release/bioc/html/ComplexHeatmap.html
发现现在的页面版本是Bioconductor version: Release (3.15)
,不确定版本可以使用下面尝试加载命令,会提示正确版本信息:
if (!require("BiocManager", quietly = TRUE))
install.packages("BiocManager")
随后更新BiocManager
版本至3.15
,此时就会更新所有的Bioconductor包(比较费时):
BiocManager::install(version = '3.15')
(2)更新所有包
更新CRAN, Bioconductor和Github上的R包:
require(rvcheck)
update_all()
可以考虑将该命令放入系统中,每个月或几个月更新一次,实现R包更新自动化,不必每次手动检查了:
rvcheck::update_all()
3. R包devtools下载
为了更好的使用Github中的R包,需要下载devtools以此来获得Github中的野包(未被CRAN收录):
打开R4.2.1,下载devtools:
install.packages("devtools")
该软件包含很多依赖包,下载到后面出现报错:
usethis R包不能安装,提示gert这个依赖包不能安装。
仔细看报错信息,看Ubuntu那行原来是缺少系统文件:
Configuration failed to find libgit2 library. Try installing:
* brew: libgit2 (MacOS)
* deb: libgit2-dev (Debian, Ubuntu, etc)
* rpm: libgit2-devel (Fedora, CentOS, RHEL)
下载系统文件:
sudo apt install libgit2-dev
继续下载遇到同样的错误,看Ubuntu那行原来是缺少系统文件:
Configuration failed to find the harfbuzz freetype2 fribidi library. Try installing:
* deb: libharfbuzz-dev libfribidi-dev (Debian, Ubuntu, etc)
* rpm: harfbuzz-devel fribidi-devel (Fedora, EPEL)
* csw: libharfbuzz_dev libfribidi_dev (Solaris)
* brew: harfbuzz fribidi (OSX)
If harfbuzz freetype2 fribidi is already installed, check that 'pkg-config' is in your
PATH and PKG_CONFIG_PATH contains a harfbuzz freetype2 fribidi.pc file. If pkg-config
is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:
R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'
-------------------------- [ERROR MESSAGE] ---------------------------
<stdin>:1:10: fatal error: hb-ft.h: 没有那个文件或目录
compilation terminated.
--------------------------------------------------------------------
ERROR: configuration failed for package ‘textshaping’
* removing ‘/home/cfc424/R/x86_64-pc-linux-gnu-library/4.2/textshaping’
下载的程序包在
‘/tmp/RtmpBDL8b7/downloaded_packages’里
Warning message:
In install.packages("textshaping") :
下载系统文件:
sudo apt install libharfbuzz-dev libfribidi-dev
再次运行install.packages("devtools")
,顺利完成,成功安装devtools。
4. 总结
R语言版本和R包版本是要常常更新的,否则时间长了,容易出现软件安装无法安装依赖包情况,这个时候,如果软件依赖过多,就只能重新下载R语言了,不必折腾过老的R版本,毫无价值。
有点问题,还是存在一些包版本未升级,只能用的时候自己update一下了。
参考:
https://cloud.r-project.org/ (R官网)
https://cloud.r-project.org/bin/linux/ubuntu/fullREADME.html (下载R和R包全文档)
https://github.com/r-lib/textshaping/issues/21 (devtools安装中报错查询)
https://askubuntu.com/questions/65081/what-are-the-implications-of-no-install-recommends-apt-get-install