这里以安装tidyverse报错为例,应该其他包也可能会遇到类似的问题。
以正常途径安装tidyverse:
install.packages("tidyverse")
出现类似如下报错信息:
Error: package or namespace load failed for ‘dbplyr’ in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]): namespace ‘dplyr’ 1.0.0 is being loaded, but >= 1.0.4 is required
报错信息是大致是说在安装或使用某个R包时,它的依赖包dplyr不能正常使用,原因是版本过低,目前版本为1.0.0,但需要1.0.4或以上版本才可以。
解决思路当然是升级包的版本或安装新版本的包,但你会发现正常使用install.packages安装的包还是旧版本的,应该是受机器上R本身版本所限,所以需要通过不太正常的途径安装这个包。
具体操作步骤如下:
- 去CRAN官网下载新版本的R包源码
CRAN - Package dplyr
- 解压源码包
tar xzvf dplyr_1.0.7.tar.gz
- 在terminal里执行如下命令:
R CMD INSTALL -l /home/suhui/R/x86_64-pc-linux-gnu-library/4.0 /home/suhui/R/x86_64-pc-linux-gnu-library/dplyr
第一个参数为R的library的绝对路径,第二个参数为即将安装的源码包所在的绝对路径。
显示安装成功:
suhui@suhui-System-Product-Name:4.0$ R CMD INSTALL -l /home/suhui/R/x86_64-pc-linux-gnu-library/4.0 /home/suhui/R/x86_64-pc-linux-gnu-library/dplyrMicrosoft R Open 4.0.2The enhanced R distribution from MicrosoftMicrosoft packages Copyright (C) 2020 Microsoft CorporationUsing the Intel MKL for parallel mathematical computing (using 8 cores).Default CRAN mirror snapshot taken on 2020-07-16.See: https://mran.microsoft.com/.* installing *source* package ‘dplyr’ ...** package ‘dplyr’ successfully unpacked and MD5 sums checked** using staged installation** libsg++ -I/opt/microsoft/ropen/4.0.2/lib64/R/include -DNDEBUG -DU_STATIC_IMPLEMENTATION -fpic -DU_STATIC_IMPLEMENTATION -O2 -g -c chop.cpp -o chop.og++ -I/opt/microsoft/ropen/4.0.2/lib64/R/include -DNDEBUG -DU_STATIC_IMPLEMENTATION -fpic -DU_STATIC_IMPLEMENTATION -O2 -g -c filter.cpp -o filter.og++ -I/opt/microsoft/ropen/4.0.2/lib64/R/include -DNDEBUG -DU_STATIC_IMPLEMENTATION -fpic -DU_STATIC_IMPLEMENTATION -O2 -g -c funs.cpp -o funs.og++ -I/opt/microsoft/ropen/4.0.2/lib64/R/include -DNDEBUG -DU_STATIC_IMPLEMENTATION -fpic -DU_STATIC_IMPLEMENTATION -O2 -g -c group_by.cpp -o group_by.og++ -I/opt/microsoft/ropen/4.0.2/lib64/R/include -DNDEBUG -DU_STATIC_IMPLEMENTATION -fpic -DU_STATIC_IMPLEMENTATION -O2 -g -c group_data.cpp -o group_data.og++ -I/opt/microsoft/ropen/4.0.2/lib64/R/include -DNDEBUG -DU_STATIC_IMPLEMENTATION -fpic -DU_STATIC_IMPLEMENTATION -O2 -g -c imports.cpp -o imports.og++ -I/opt/microsoft/ropen/4.0.2/lib64/R/include -DNDEBUG -DU_STATIC_IMPLEMENTATION -fpic -DU_STATIC_IMPLEMENTATION -O2 -g -c init.cpp -o init.og++ -I/opt/microsoft/ropen/4.0.2/lib64/R/include -DNDEBUG -DU_STATIC_IMPLEMENTATION -fpic -DU_STATIC_IMPLEMENTATION -O2 -g -c mask.cpp -o mask.og++ -I/opt/microsoft/ropen/4.0.2/lib64/R/include -DNDEBUG -DU_STATIC_IMPLEMENTATION -fpic -DU_STATIC_IMPLEMENTATION -O2 -g -c mutate.cpp -o mutate.og++ -I/opt/microsoft/ropen/4.0.2/lib64/R/include -DNDEBUG -DU_STATIC_IMPLEMENTATION -fpic -DU_STATIC_IMPLEMENTATION -O2 -g -c slice.cpp -o slice.og++ -I/opt/microsoft/ropen/4.0.2/lib64/R/include -DNDEBUG -DU_STATIC_IMPLEMENTATION -fpic -DU_STATIC_IMPLEMENTATION -O2 -g -c summarise.cpp -o summarise.og++ -shared -L/opt/microsoft/ropen/4.0.2/lib64/R/lib -o dplyr.so chop.o filter.o funs.o group_by.o group_data.o imports.o init.o mask.o mutate.o slice.o summarise.o -L/opt/microsoft/ropen/4.0.2/lib64/R/lib -lRinstalling to /home/suhui/R/x86_64-pc-linux-gnu-library/4.0/00LOCK-dplyr/00new/dplyr/libs** R** data*** moving datasets to lazyload DB** inst** byte-compile and prepare package for lazy loadingMicrosoft R Open 4.0.2The enhanced R distribution from MicrosoftMicrosoft packages Copyright (C) 2020 Microsoft CorporationUsing the Intel MKL for parallel mathematical computing (using 8 cores).Default CRAN mirror snapshot taken on 2020-07-16.See: https://mran.microsoft.com/.** help*** installing help indices*** copying figures** building package indicesMicrosoft R Open 4.0.2The enhanced R distribution from MicrosoftMicrosoft packages Copyright (C) 2020 Microsoft CorporationUsing the Intel MKL for parallel mathematical computing (using 8 cores).Default CRAN mirror snapshot taken on 2020-07-16.See: https://mran.microsoft.com/.** installing vignettes** testing if installed package can be loaded from temporary locationMicrosoft R Open 4.0.2The enhanced R distribution from MicrosoftMicrosoft packages Copyright (C) 2020 Microsoft CorporationUsing the Intel MKL for parallel mathematical computing (using 8 cores).Default CRAN mirror snapshot taken on 2020-07-16.See: https://mran.microsoft.com/.** checking absolute paths in shared objects and dynamic libraries** testing if installed package can be loaded from final locationMicrosoft R Open 4.0.2The enhanced R distribution from MicrosoftMicrosoft packages Copyright (C) 2020 Microsoft CorporationUsing the Intel MKL for parallel mathematical computing (using 8 cores).Default CRAN mirror snapshot taken on 2020-07-16.See: https://mran.microsoft.com/.** testing if installed package keeps a record of temporary installation path* DONE (dplyr)
再次在R的console里安装tidyverse:
> install.packages("tidyverse")Installing package into ‘/home/suhui/R/x86_64-pc-linux-gnu-library/4.0’(as ‘lib’ is unspecified) % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed100 696k 100 696k 0 0 350k 0 0:00:01 0:00:01 --:--:-- 350kMicrosoft R Open 4.0.2The enhanced R distribution from MicrosoftMicrosoft packages Copyright (C) 2020 Microsoft CorporationUsing the Intel MKL for parallel mathematical computing (using 8 cores).Default CRAN mirror snapshot taken on 2020-07-16.See: https://mran.microsoft.com/.* installing *source* package ‘tidyverse’ ...** package ‘tidyverse’ successfully unpacked and MD5 sums checked** using staged installation** R** inst** byte-compile and prepare package for lazy loadingMicrosoft R Open 4.0.2The enhanced R distribution from MicrosoftMicrosoft packages Copyright (C) 2020 Microsoft CorporationUsing the Intel MKL for parallel mathematical computing (using 8 cores).Default CRAN mirror snapshot taken on 2020-07-16.See: https://mran.microsoft.com/.** help*** installing help indices*** copying figures** building package indicesMicrosoft R Open 4.0.2The enhanced R distribution from MicrosoftMicrosoft packages Copyright (C) 2020 Microsoft CorporationUsing the Intel MKL for parallel mathematical computing (using 8 cores).Default CRAN mirror snapshot taken on 2020-07-16.See: https://mran.microsoft.com/.** installing vignettes** testing if installed package can be loaded from temporary locationMicrosoft R Open 4.0.2The enhanced R distribution from MicrosoftMicrosoft packages Copyright (C) 2020 Microsoft CorporationUsing the Intel MKL for parallel mathematical computing (using 8 cores).Default CRAN mirror snapshot taken on 2020-07-16.See: https://mran.microsoft.com/.** testing if installed package can be loaded from final locationMicrosoft R Open 4.0.2The enhanced R distribution from MicrosoftMicrosoft packages Copyright (C) 2020 Microsoft CorporationUsing the Intel MKL for parallel mathematical computing (using 8 cores).Default CRAN mirror snapshot taken on 2020-07-16.See: https://mran.microsoft.com/.** testing if installed package keeps a record of temporary installation path* DONE (tidyverse)The downloaded source packages are in‘/tmp/RtmpkDlsxv/downloaded_packages’
安装成功,载入tidyverse:
> library(tidyverse)── Attaching packages ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse 1.3.0 ──✓ ggplot2 3.3.5 ✓ purrr 0.3.4✓ tibble 3.1.3 ✓ dplyr 1.0.7✓ tidyr 1.1.3 ✓ stringr 1.4.0✓ readr 2.0.0 ✓ forcats 0.5.1── Conflicts ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──x dplyr::filter() masks stats::filter()x dplyr::lag() masks stats::lag()
可以正常使用了。
希望可以帮助到后来遇到类似问题的大家。
补充说明一下,我的系统是Ubuntu 20.04,其他版本的Ubuntu或CentOS问题应该也不大,Window系统应该就不适用了,抱歉。