在安装 ggpubr 时,出现报错。
系统:CentOS7.9
$ R --version
R version 4.3.2 (2023-10-31) – “Eye Holes”
$ gcc --version
gcc (GCC) 12.3.0
$ sudo yum install cmake3
> system("/usr/bin/cmake3 --version")
> install.packages("nloptr")
> install.packages("minqa")
...
gcc编译语句中出现:WARNING: ignoring environment value of R_HOME
导致红字:
/bin/ld: cannot find WARNING:: No such file or directory
/bin/ld: cannot find ignoring: No such file or directory
/bin/ld: cannot find environment: No such file or directory
/bin/ld: cannot find value: No such file or directory
/bin/ld: cannot find of: No such file or directory
/bin/ld: cannot find R_HOME: No such file or directory
collect2: error: ld returned 1 exit status
make: *** [lme4.so] Error 1
但是我的R环境能找到变量R_HOME:
> system("echo $R_HOME")
/opt/R/4.3.2/lib64/R
https://github.com/rstudio/renv/issues/417
This looks a little suspicious. Is it possible that you've set some environment variables to point to a separate (older?) R installation? What is the output of:
Sys.getenv("R_HOME") in your session?
> Sys.getenv("R_HOME")
[1] "/opt/R/4.3.2/lib64/R"
首先下载R包到本地:
$ cd /picb/jinlab/wangjl/others/shenwh/PTC/output/
$ wget https://mirrors.tuna.tsinghua.edu.cn/CRAN/src/contrib/minqa_1.2.7.tar.gz
解压缩
$ tar zxvf minqa_1.2.7.tar.gz
$ cd minqa
查问题关键词:
$ find . | xargs grep -in "R_home" --color=auto
找到问题文件:echo $(R_HOME) 确实不识别
而去掉圆括号正常识别:
$ echo $R_HOME
/opt/R/4.3.2/lib64/R
修改它: 就是删除R_HOME外的圆括号:
$ vim src/Makevars
#PKG_LIBS = `$(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()"` 修改为:
PKG_LIBS = `$R_HOME/bin/Rscript -e "Rcpp:::LdFlags()"`
重新构建R包:
$ cd ..
$ R CMD build minqa
["/picb/jinlab/wangjl/R/x86_64-pc-linux-gnu-library/4.3","/opt/R/4.3.2/lib64/R/library"]
* checking for file ‘minqa/DESCRIPTION’ ... OK
* preparing ‘minqa’:
* checking DESCRIPTION meta-information ... OK
* cleaning src
* checking for LF line-endings in source and make files and shell scripts
* checking for empty or unneeded directories
* building ‘minqa_1.2.7.tar.gz’
在R中安装该包:
> install.packages("/picb/jinlab/wangjl/others/shenwh/PTC/output/minqa_1.2.7.tar.gz")
> packageVersion("minqa")
[1] ‘1.2.7’
上文忘了记录报错过程了,和这个几乎一模一样:
> install.packages("lme4")
g++ -std=gnu++11 -shared -L/opt/R/4.3.2/lib64/R/lib -L/usr/local/lib64 -o lme4.so external.o glmFamily.o optimizer.o predModule.o respModule.o WARNING: ignoring environment value of R_HOME -L/opt/R/4.3.2/lib64/R/lib -lR
注意以上编译语句中出现了一句警告:WARNING: ignoring environment value of R_HOME
导致无法识别,引发进一步报错:
/bin/ld: cannot find WARNING:: No such file or directory
/bin/ld: cannot find ignoring: No such file or directory
/bin/ld: cannot find environment: No such file or directory
/bin/ld: cannot find value: No such file or directory
/bin/ld: cannot find of: No such file or directory
/bin/ld: cannot find R_HOME: No such file or directory
collect2: error: ld returned 1 exit status
make: *** [lme4.so] Error 1
下载该包:
$ wget https://mirrors.tuna.tsinghua.edu.cn/CRAN/src/contrib/lme4_1.1-35.3.tar.gz
$ tar zxvf lme4_1.1-35.3.tar.gz
修改
$ vim lme4/src/Makevars
#PKG_LIBS = `$(R_HOME)/bin/Rscript --vanilla -e "Rcpp:::LdFlags()"` #去掉R_HOME外的圆括号,修改为:
PKG_LIBS = `$R_HOME/bin/Rscript --vanilla -e "Rcpp:::LdFlags()"`
重新构建
$ R CMD build lme4
报错 rror: processing vignette 'lmer.Rnw' failed with diagnostics:
there is no package called 'gamm4'
似乎是循环依赖:
> install.packages("gamm4")
它又开始先安装 lme4,而该包还是报错
使用文件夹安装呢?可以!
$ R CMD INSTALL lme4
> packageVersion("lme4")
[1] ‘1.1.35.3’
接着一切顺利了。
> install.packages("ggpubr")
加载:
> packageVersion("ggpubr")
[1] ‘0.6.0’
> library("ggpubr")
Loading required package: ggplot2
>
1)找到 HDF5 的根目录:
$ which h5cc
~/.local/bin/h5cc
2)在shell下逐行执行:
export HDF5_DIR=/home/wangjl/.local/
export LD_LIBRARY_PATH=$HDF5_DIR/lib:$LD_LIBRARY_PATH
export CFLAGS="-I$HDF5_DIR/include"
export LDFLAGS="-L$HDF5_DIR/lib"
Rscript -e 'if (!requireNamespace("BiocManager", quietly = TRUE)) install.packages("BiocManager"); BiocManager::install("rhdf5")'
注: 最后一步在shell R中执行失败。在shell中可以!?
3) 检查,shell R 或 Rstudio:
R
> library("rhdf5")
> packageVersion("rhdf5") #‘2.46.1’
$(R_HOME) 是函数调用!
参考 https://blog.csdn.net/evilswords/article/details/12349187
如 $(strip ) 名称:去空格函数——strip。
所以,我认为R包原作者们是写错了,应该去掉R_HOME外的圆括号,还原它为一个普通变量名。