专栏名称: 生信媛
生信媛,从1人分享,到8人同行。坚持分享生信入门方法与课程,持续记录生信相关的分析pipeline, python和R在生物信息学中的利用。内容涵盖服务器使用、基因组转录组分析以及群体遗传。
目录
相关文章推荐
51好读  ›  专栏  ›  生信媛

R4.0的源码安装——以mac为例

生信媛  · 公众号  · 生物  · 2020-08-03 09:38

正文

装了一堆东西回来,已经忘了最初要做的是啥。

太长不看版

其实就是缺什么安装什么。每个人情况可能都不太一样。对于我的mac上,如下:

  • configure之前需要安装:
    • gcc
    • xz
    • pcre2

安装方法:brew

brew install gccbrew install xzbrew install pcre2
  • make之前需要安装
    • JDK:直接下载dmg安装
    • Mactex(可选):直接下载dmg安装或者 brew cask install mactex

正文

起因

在R3.6.3下安装"psych"包,发现其依赖包‘mnormt’只支持R4.0以上。

> install.packages("psych")Warning in install.packages :  dependency ‘mnormt’ is not available
There is a binary version available but the source version is later: binary source needs_compilationpsych 1.9.12.31 2.0.7 FALSE
installing the source package ‘psych’
trying URL 'https://cran.rstudio.com/src/contrib/psych_2.0.7.tar.gz'Content type 'application/x-gzip' length 1743492 bytes (1.7 MB)==================================================downloaded 1.7 MB
ERROR: dependency ‘mnormt’ is not available for package ‘psych’* removing ‘/Library/Frameworks/R.framework/Versions/3.6/Resources/library/psych’Warning in install.packages : installation of package ‘psych’ had non-zero exit status
The downloaded source packages are in ‘/private/var/folders/2m/m8nlj_2521d01sz7vypnvh940000gn/T/RtmpqaVH0v/downloaded_packages’

但是在mac下,安装R的pkg似乎没有办法使得两个版本的R并存。于是开始了我漫长的R4.0源码安装之旅。

从R4.0的下载和安装开始,逐渐走向不归路。

# 进入你常用的软件下载路径。我这里是srccd src# 下载wget https://cran.r-project.org/src/base/R-4/R-4.0.2.tar.gz# 解压tar -zxvf tar -zxvf R-4.0.2.tar.gzcd R-4.0.2# 查看configure的设置参数可以用下边命令# ./configure -h# 正式configure./configure --prefix=$HOME/opt --with-x=no --enable-R-shlib
  • --enable-R-shlib :build the shared/dynamic library 'libR' [no],要使底层R共享库对RStudio服务器可用,需要enable-R-shlib选项。
  • --with-x : use the X Window System

结果报错了:

checking whether we are using the GNU Fortran compiler... nochecking whether  accepts -g... noconfigure: error: No Fortran compiler found

安装gfortran

$ brew search gfortranWarning: Error searching on GitHub: curl failed!   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current                                 Dload  Upload   Total   Spent    Left  Speed  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0curl: (7) Failed to connect to api.github.com port 443: Connection refused
GNU Fortran is part of the GCC formula: brew install gcc

好的,GNU Fortran is part of the GCC formula,那我就根据提示安装GCC吧。

brew install gcc

再来一次:

./configure --prefix=$HOME/opt --with-x=no --enable-R-shlib# configure: error: "liblzma library and headers are required"

搜索了一下,发现是因为缺少了xz库。好吧,老老实实安装。

brew install xz

也可以到这:http://R.research.att.com/libs/下载安装。

  • 解决方法参考了这篇:《Install R with shared library in OSX - liblzma library missing》:https://stackoverflow.com/questions/40222371/install-r-with-shared-library-in-osx-liblzma-library-missing

不气馁,再来一次:

./configure --prefix=$HOME/opt --with-x=no --enable-R-shlib

新的报错

configure: error: PCRE2 library and headers are required, or use --with-pcre1 and PCRE >= 8.32 with UTF-8 support

在CRAN给的R安装指南《R Installation and Administration》章节《Essential-programs-and-libraries》(https://cran.r-project.org/doc/manuals/r-devel/R-admin.html#Essential-programs-and-libraries)里是这么描述的:

Either PCRE1 (version 8.32 or later, formerly known as just PCRE) or PCRE2 is required: PCRE2 is preferred and using PCRE1 requires configure option --with-pcre1. Only the 8-bit library and headers are needed if these are packaged separately. JIT support (optional) is desirable for the best performance. For PCRE2 >= 10.30 (which is desirable as matching has been re-written not to use recursion and the Unicode tables were updated to version 10)
./configure --enable-jit
suffices. If building PCRE1 for use with R a suitable configure command might be
./configure --enable-utf --enable-unicode-properties --enable-jit --disable-cpp
The --enable-jit flag is supported for most common CPUs. (See also the comments for Solaris.)
Some packages require the ‘Unicode properties’ which are optional for PCRE1: support for this and JIT can be checked at run-time by calling pcre_config().

PCRE有PCRE1和PCRE2两个版本。更建议使用PCRE2。好的。来装吧:

brew install pcre2
  • 附:关于 pcre --enable-jit :《pcrejit man page》(https://www.pcre.org/original/doc/html/pcrejit.html)

再来一次:

./configure --prefix=$HOME/opt --with-x=no --enable-R-shlib

好像可以了。来编译试试:

make

提示需要安装JDK。

到这里https://www.oracle.com/java/technologies/javase-jdk14-downloads.html下载对应版本安装。我下载的是dmg版本:

好了。继续往前

make installmake install-info  # To install info and PDF versions of the manualsmake check

make check : 安装后的检测。会生成一个tests目录。(个人猜测)原理应该是比较R脚本出来的结果跟它理应出来的结果进行比较。

在'reg-packages.R'这一个检测中报错了。

running code in 'array-subset.R' ... OKrunning code in 'reg-tests-1a.R' ... OKrunning code in 'reg-tests-1b.R' ... OKrunning code in 'reg-tests-1c.R' ... OKrunning code in 'reg-tests-1d.R' ... OKrunning code in 'reg-tests-2.R' ... OK






请到「今天看啥」查看全文


推荐文章
创意科技生活  ·  人难做,做别人嘴里的人,更难!
8 年前
Hi科技你好  ·  撸起袖子,找到真爱!
8 年前
photoshop大师  ·  泰国广告又一次刷新了我的认知!
7 年前
上下五千年故事  ·  魏晋南北朝为啥被称为“乱世”?
7 年前