通过自制软件安装 R 3.x

Posted

技术标签:

【中文标题】通过自制软件安装 R 3.x【英文标题】:Install R 3.x via homebrew 【发布时间】:2020-11-04 06:27:18 【问题描述】:

R 公式https://github.com/Homebrew/homebrew-core/commits/master/Formula/r.rb 最近从版本 3.6.3 升级到了 4.0。版本 4 中有一些向后不兼容的更改,所以我想在我的系统上安装 3.x 和 4.x 以进行测试。

这可以用自制软件实现吗?对brew install r@3.6 的简单尝试只会给我No available formula with the name "r@3.6"

(除此之外:从 3.6 升级到 4.0 的过程相当偷偷摸摸地发生在我的系统上,我做了一个 brew upgrade dvc 并升级了一些依赖项 [Installing dependencies for dvc: c-ares, protobuf, grpc, gcc, openblas, sqlite, python@3.8, numpy, zstd and apache-arrow],然后是大量依赖项:

==> Upgrading 42 dependents:
ansible 2.9.6_1 -> 2.9.10, ansible 2.9.6_1 -> 2.9.10, awscli 2.0.7 -> 2.0.28_1,
 awscli 2.0.7 -> 2.0.28_1, cython 0.29.10 -> 0.29.20, cassandra 3.11.4 -> 3.11.6_2,
 ffmpeg 4.2.2_2 -> 4.3_2, ffmpeg 4.2.2_2 -> 4.3_2, gdal 2.4.4_4 -> 3.1.1_2,
 gdal 2.4.4_4 -> 3.1.1_2, gdal 2.4.4_4 -> 3.1.1_2, gdal 2.4.4_4 -> 3.1.1_2,
 gdal 2.4.4_4 -> 3.1.1_2, gdal 2.4.4_4 -> 3.1.1_2, glib 2.64.2 -> 2.64.3, glib 2.64.2 -> 2.64.3,
 graphviz 2.42.3 -> 2.44.0, graphviz 2.42.3 -> 2.44.0, harfbuzz 2.6.4 -> 2.6.8,
 hdf5 1.12.0 -> 1.12.0_1, imagemagick 7.0.10-6_1 -> 7.0.10-23,
 imagemagick 7.0.10-6_1 -> 7.0.10-23, ipython 7.13.0 -> 7.16.1, jupyterlab 2.1.0 -> 2.1.5,
 libdap 3.20.5 -> 3.20.6, libdap 3.20.5 -> 3.20.6, libheif 1.6.2_1 -> 1.7.0,
 libheif 1.6.2_1 -> 1.7.0, maxima 5.43.2 -> 5.44.0, maxima 5.43.2 -> 5.44.0,
 netcdf 4.7.4 -> 4.7.4_1, pipenv 2018.11.26_3 -> 2020.6.2, pipenv 2018.11.26_3 -> 2020.6.2,
 poppler 0.87.0 -> 0.90.0, poppler 0.87.0 -> 0.90.0, python 3.7.7 -> 3.7.8,
 python-yq 2.7.2 -> 2.10.1, qcachegrind 18.04.3_1 -> 19.08.3, r 3.6.3_1 -> 4.0.2_1,
 r 3.6.3_1 -> 4.0.2_1, shared-mime-info 1.15 -> 2.0, shared-mime-info 1.15 -> 2.0

这就是我尝试重新安装 R 3.6 的原因。)

【问题讨论】:

【参考方案1】:

由于R 3.6.3 没有在上游积极维护,因此 homebrew-core 没有针对它的版本化公式。安装最新的 3.6.3 版本有一些 hacky 方法。

$ cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core # switch to your local homebrew-core folder

$ git reset --hard c3a244c627e # effective reset to the most recent r3.6.3 edition
Updating files: 100% (3680/3680), done.
HEAD is now at c3a244c627e r: update 3.6.3_2 bottle.
$ git checkout -b r-3.6.3 # this would prevent messing up your source tree
Switched to a new branch 'r-3.6.3'

$ brew reinstall r # this would reinstall 3.6.3_2

$ git checkout master # checkout back to source tree

安装日志

==> Downloading https://homebrew.bintray.com/bottles/gcc-9.3.0_1.mojave.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/de8319322428721741a0dc41dfdf2eece80e0215a7a4a861e0e206a9bfbca583?response-
######################################################################## 100.0%
==> Downloading https://homebrew.bintray.com/bottles/openblas-0.3.9.mojave.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/15116c0a8d1f359f83761de72835021cbad6a814cf7fd53cc93428b522f06dda?response-
######################################################################## 100.0%
==> Downloading https://homebrew.bintray.com/bottles/r-3.6.3_2.mojave.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/c6d4210a241f9466804d5660b467afb6f59d2150e43288b1c66e47387ff43f6e?response-
######################################################################## 100.0%
==> Reinstalling r
==> Installing dependencies for r: gcc and openblas
==> Installing r dependency: gcc
==> Pouring gcc-9.3.0_1.mojave.bottle.tar.gz
?  /usr/local/Cellar/gcc/9.3.0_1: 1,463 files, 292MB
==> Installing r dependency: openblas
==> Pouring openblas-0.3.9.mojave.bottle.tar.gz
==> Caveats
openblas is keg-only, which means it was not symlinked into /usr/local,
because macOS provides BLAS in Accelerate.framework.

For compilers to find openblas you may need to set:
  export LDFLAGS="-L/usr/local/opt/openblas/lib"
  export CPPFLAGS="-I/usr/local/opt/openblas/include"

For pkg-config to find openblas you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/openblas/lib/pkgconfig"

==> Summary
?  /usr/local/Cellar/openblas/0.3.9: 23 files, 119.7MB
==> Installing r
==> Pouring r-3.6.3_2.mojave.bottle.tar.gz
?  /usr/local/Cellar/r/3.6.3_2: 2,122 files, 58.2MB
==> Caveats
==> openblas
openblas is keg-only, which means it was not symlinked into /usr/local,
because macOS provides BLAS in Accelerate.framework.

For compilers to find openblas you may need to set:
  export LDFLAGS="-L/usr/local/opt/openblas/lib"
  export CPPFLAGS="-I/usr/local/opt/openblas/include"

For pkg-config to find openblas you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/openblas/lib/pkgconfig"

版本检查验证

$ r --version
R version 3.6.3 (2020-02-29) -- "Holding the Windsock"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin18.7.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under the terms of the
GNU General Public License versions 2 or 3.
For more information about these matters see
https://www.gnu.org/licenses/.

传统公式

除了您可以通过 hacky 方式安装之外,我还为此提交了遗留公式。 https://github.com/Homebrew/homebrew-core/pull/58063

【讨论】:

太棒了,感谢您提交版本化的公式。我在那里评论了为什么它对我的情况有用。如果我执行reinstall 操作,是否也会卸载 4.0 版?我想避免这种情况,并同时安装两个版本。 您可能不能同时运行两个公式(由于 PATH 设置问题,一个肯定会影响另一个) 请注意,r 的 v3 公式中似乎没有 big_sur 的条目,因此我无法在 Mac 上再使用此方法。它说Error: Failed to load formula: r: Invalid bottle tag symbol: Treating r as a cask. 然后安装v4。还是谢谢!【参考方案2】:

请注意,r 的 v3 公式中似乎没有最新 Mac big_sur 的条目,因此 @chenrui 的方法不再适用于新版本的 Mac(上面写着 Error: Failed to load formula: r: Invalid bottle tag symbol: Treating r as a cask.

解决方案:按照他们的建议进行操作,但不要使用核心 repo,而是使用 cask repo,并且您要查看的修订版是 6d3bdc6。更新后的步骤:

cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask # cask, not core
git reset --hard 6d3bdc6
git checkout -b r-3.6.3
HOMEBREW_NO_AUTO_UPDATE=1 brew reinstall homebrew/cask/r # Will install v3 from cask (which works on newer Macs), not formula (which is unsupported on newer Macs)
git checkout master

# Finally, since brew won't link this cask automatically:
ln -s /Library/Frameworks/R.framework/Resources/bin/R /usr/local/bin

【讨论】:

以上是关于通过自制软件安装 R 3.x的主要内容,如果未能解决你的问题,请参考以下文章

如何使用自制软件在 macOS 上安装 qt4?

在没有自制软件的情况下安装了 macos catalina 中的 mongod 命令有问题?

如何使用自制软件安装 imagemagick?

如果从今年开始 EOL,如何使用自制软件安装 php 5.6?

使用自制软件在 macOS 上安装犰狳

在使用自制软件安装的 Mac 上使用 Image::Magick 注释图像