Linux中conda安装R出现 package ‘utils’ in options("defaultPackages") was not found?
问题
Linux环境下,使用conda成功安装了R4。但提示‘utils’和‘stats’包未找到,如下:
R version 4.1.3 (2022-03-10) -- "One Push-Up"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-conda-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.
During startup - Warning messages:
1: package ‘utils’ in options("defaultPackages") was not found
2: package ‘stats’ in options("defaultPackages") was not found
此时安装R包或运行其他命令都直接报错,如:
> install.packages("ggplot2")
Error in install.packages("ggplot2") :
could not find function "install.packages"
解决一
没去分析原因,在网上查了下。找到安装R环境下的库文件ldpaths,最后一行加上export EDITOR=vim
,好像可以。如下:
echo "export EDITOR=vim" >> /opt/conda/envs/r4py3/lib/R/etc/ldpaths
正常。
R version 4.1.3 (2022-03-10) -- "One Push-Up"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-conda-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.
但是,当我第二次用docker打包时,却又出现了这个玩意。说明以上方法不是根本的解决之道。
解决二
网上又查了一圈,说是conda新建的环境中没有which,安装which即可。
(r4py3) [root@a3ef4a44aa1f etc]# which
bash: which: command not found
(r4py3) [root@a3ef4a44aa1f etc]# yum install -y which
https://github.com/ContinuumIO/anaconda-issues/issues/11133
https://www.cnblogs.com/flowerbirds/p/14191783.html
确实,安装后一切又正常了。
(r4py3) [root@a3ef4a44aa1f etc]# R
R version 4.1.3 (2022-03-10) -- "One Push-Up"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-conda-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.
然而,网上仍有一些回答说他们安装which
也没用。
R depends on which, which might not be present in the conda R environment. Maybe it could be as simple as to add the which-derivation to conda?
Placing ‘which’ into the conda binary folder did however not fix the issue (the R console still complains about not being able to load stats and utils packages)
https://discourse.nixos.org/t/r-installation-within-conda-cannot-find-default-libraries/8437
一些人建议设置set R_HOME path
,也有建议重新安装其他版本的R。
我用which成功解决,后续没什么问题了,就没尝试了。还有不成功的小伙伴可以多试试多查查,大不了重新安装。
本文来自博客园,作者:生物信息与育种,转载请注明原文链接:https://www.cnblogs.com/miyuanbiotech/p/16337581.html。若要及时了解动态信息,请关注同名微信公众号:生物信息与育种。