通过homebrew安装R 3.x

4
R公式https://github.com/Homebrew/homebrew-core/commits/master/Formula/r.rb最近从版本3.6.3升级到了版本4.0。在版本4中,有一些不向后兼容的更改,因此我想在我的系统上安装3.x和4.x两个版本以进行测试。
使用Homebrew可以实现吗?尝试简单地运行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版的原因。
2个回答

5
自从上游停止维护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


太棒了,感谢您提交版本化的公式。我在那里发表了评论,解释了为什么它在我的情况下很有用。如果我执行“重新安装”操作,是否也会卸载版本4.0?我想避免这种情况,并且希望同时安装两个版本。 - Ken Williams
由于路径设置问题,您可能无法同时运行这两个公式(其中一个肯定会覆盖另一个)。 - chenrui
1
注意,在R的v3公式中似乎没有“big_sur”的条目,因此我无法在Mac上再使用此方法。它会显示“错误:无法加载公式:r:无效的瓶标记符号:将r视为桶装酒。”,然后安装v4。无论如何还是非常感谢! - Kevin Cooper

2
请注意,r的v3公式中似乎没有最新Mac big_sur的条目,因此@chenrui的方法在新版本的Mac上不再适用(它会显示“错误:无法加载公式:r:无效的瓶标记符号:将r视为cask。”)
解决方案:执行与他们建议相同的操作,但是使用cask仓库而不是核心仓库,并且您想要检出的修订版本是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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接