R语言 | 安装ggpubr R包时编译语句中出现 WARNING: ignoring environment value of R_HOME 而报错

在安装 ggpubr 时,出现报错。

1. 环境介绍

系统:CentOS7.9

$ R --version

R version 4.3.2 (2023-10-31) -- "Eye Holes"

$ gcc --version

gcc (GCC) 12.3.0

2. 缺少cmake

$ sudo yum install cmake3

> system("/usr/bin/cmake3 --version")
> install.packages("nloptr")

3. 编译语句出现 WARNING: ignoring environment value of R_HOME

> 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

1) 解释1 : 没帮助

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"

2)我怀疑就是老外没写好包,导致编译不正常,那就尝试fix它

首先下载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'

4. lme4 包也同样编译报错(同上),全命令行修改安装

上文忘了记录报错过程了,和这个几乎一模一样:

> 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'

5. 成功安装ggpubr包

接着一切顺利了。

> install.packages("ggpubr")

加载:
> packageVersion("ggpubr")
[1] '0.6.0'
> library("ggpubr")
Loading required package: ggplot2
>

10. 那么,Makevars 中圆括号什么意思?

$(R_HOME) 是函数调用!

参考 https://blog.csdn.net/evilswords/article/details/12349187

如 $(strip ) 名称:去空格函数------strip。

所以,我认为R包原作者们是写错了,应该去掉R_HOME外的圆括号,还原它为一个普通变量名。

Ref

相关推荐
吾爱星辰1 小时前
Kotlin 处理字符串和正则表达式(二十一)
java·开发语言·jvm·正则表达式·kotlin
ChinaDragonDreamer1 小时前
Kotlin:2.0.20 的新特性
android·开发语言·kotlin
IT良1 小时前
c#增删改查 (数据操作的基础)
开发语言·c#
Kalika0-02 小时前
猴子吃桃-C语言
c语言·开发语言·数据结构·算法
_.Switch2 小时前
Python Web 应用中的 API 网关集成与优化
开发语言·前端·后端·python·架构·log4j
代码雕刻家2 小时前
课设实验-数据结构-单链表-文教文化用品品牌
c语言·开发语言·数据结构
一个闪现必杀技2 小时前
Python入门--函数
开发语言·python·青少年编程·pycharm
Fan_web2 小时前
jQuery——事件委托
开发语言·前端·javascript·css·jquery
龙图:会赢的2 小时前
[C语言]--编译和链接
c语言·开发语言
XKSYA(小巢校长)4 小时前
NatGo我的世界联机篇
开发语言·php