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

相关推荐
Once_day5 分钟前
C++之fmt库介绍和使用(1)
开发语言·c++·fmt
摆烂且佛系11 分钟前
FastByteArrayOutputStream和ByteArrayInputStream有什么区别
java·开发语言
Chandler2419 分钟前
Go语言:json 作用和语法
开发语言·golang·json
凤年徐22 分钟前
【C/C++】自定义类型:结构体
c语言·开发语言·c++·经验分享·笔记·算法
能来帮帮蒟蒻吗40 分钟前
Python -将MP4文件转为GIF图片
开发语言·python·学习·视频
忆源43 分钟前
【Qt】之音视频编程2:QtAV的使用篇
开发语言·qt·音视频
程序员阿鹏1 小时前
Git的安装和配置(idea中配置Git)
java·开发语言·ide·git·intellij-idea·idea
景天科技苑1 小时前
【Rust trait特质】如何在Rust中使用trait特质,全面解析与应用实战
开发语言·后端·rust·trait·rust trait·rust特质
PacosonSWJTU1 小时前
python使用matplotlib画图
开发语言·python·matplotlib
Inverse1621 小时前
C语言_自定义类型:结构体
c语言·开发语言·算法