装了一堆东西回来,已经忘了最初要做的是啥。
太长不看版
其实就是缺什么安装什么。每个人情况可能都不太一样。对于我的mac上,如下:
安装方法:brew
brew install gcc
brew install xz
brew install pcre2
-
-
-
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_compilation
psych 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的下载和安装开始,逐渐走向不归路。
# 进入你常用的软件下载路径。我这里是src
cd 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.gz
cd 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... no
checking whether accepts -g... no
configure: error: No Fortran compiler found
安装gfortran
$ brew search gfortran
Warning: 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吧。
再来一次:
./configure --prefix=$HOME/opt --with-x=no --enable-R-shlib
# configure: error: "liblzma library and headers are required"
搜索了一下,发现是因为缺少了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。好的。来装吧:
-
附:关于
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
好像可以了。来编译试试:
提示需要安装JDK。
到这里https://www.oracle.com/java/technologies/javase-jdk14-downloads.html下载对应版本安装。我下载的是dmg版本:
好了。继续往前
make install
make install-info # To install info and PDF versions of the manuals
make check
make check
: 安装后的检测。会生成一个tests目录。(个人猜测)原理应该是比较R脚本出来的结果跟它理应出来的结果进行比较。
在'reg-packages.R'这一个检测中报错了。
running code in 'array-subset.R' ... OK
running code in 'reg-tests-1a.R' ... OK
running code in 'reg-tests-1b.R' ... OK
running code in 'reg-tests-1c.R' ... OK
running code in 'reg-tests-1d.R' ... OK
running code in 'reg-tests-2.R' ... OK