尽管系统上有可用的 tcl-tk,但 R 包 geoR 不会安装在 macOS 上

R package geoR won't install on macOS despite available tcl-tk on the system

我已经通过 brew 安装了 R 和 RStudio。对于一个项目,我需要 R 库 geoR 中的一个函数,该函数又依赖于 tcl-tk。我也通过 brew 安装了它:brew install tcl-tk。但是,尝试安装 geoR 仍然会导致以下错误 - 我没有得到。 重新安装 R/RStudio 没有帮助。也没有重新启动我的 Mac。哦,尝试从 CRAN 下载的二进制文件安装 geoR 也无济于事……最后,尝试从 R 网站安装 tcl-tk 包也没有解决这个问题。

我还在 brewGitHub 上发布了这个 - 但也许其他人访问了 Whosebug 的领域。

我的brew状态

brew config
HOMEBREW_VERSION: 1.5.2
ORIGIN: https://github.com/Homebrew/brew
HEAD: 60a30e966b7cece5bd4823dae3fb981ab85106ea
Last commit: 11 days ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 8c1c4f86a269cb23d9d92008abf1a37eabb297b6
Core tap last commit: 2 hours ago
HOMEBREW_PREFIX: /usr/local
CPU: quad-core 64-bit skylake
Homebrew Ruby: 2.3.3 => /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby
Clang: 9.0 build 900
Git: 2.16.1 => /usr/local/bin/git
Curl: 7.54.0 => /usr/bin/curl
Perl: /usr/bin/perl
Python: /usr/local/opt/python/libexec/bin/python => /usr/local/Cellar/python/2.7.14_2/Frameworks/Python.framework/Versions/2.7/bin/python2.7
Ruby: /usr/bin/ruby => /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby
Java: 9.0.1
macOS: 10.13.3-x86_64
Xcode: N/A
CLT: 9.2.0.0.1.1510905681
X11: 2.7.11 => /opt/X11

错误

* installing *source* package ‘geoR’ ...
** package ‘geoR’ successfully unpacked and MD5 sums checked
** libs
clang -I/usr/local/Cellar/r/3.4.3_1/lib/R/include -DNDEBUG   -I/usr/local/opt/gettext/include -I/usr/local/opt/readline/include -I/usr/local/include   -fPIC  -g -O2  -c geoR.c -o geoR.o
clang -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/usr/local/Cellar/r/3.4.3_1/lib/R/lib -L/usr/local/opt/gettext/lib -L/usr/local/opt/readline/lib -L/usr/local/lib -o geoR.so geoR.o -L/usr/local/Cellar/r/3.4.3_1/lib/R/lib -lR -lintl -Wl,-framework -Wl,CoreFoundation
installing to /usr/local/lib/R/3.4/site-library/geoR/libs
** R
** data
*** moving datasets to lazyload DB
** inst
** preparing package for lazy loading
Warning: S3 methods ‘as.character.tclObj’, ‘as.character.tclVar’, ‘as.double.tclObj’, ‘as.integer.tclObj’, ‘as.logical.tclObj’, ‘as.raw.tclObj’, ‘print.tclObj’, ‘[[.tclArray’, ‘[[<-.tclArray’, ‘$.tclArray’, ‘$<-.tclArray’, ‘names.tclArray’, ‘names<-.tclArray’, ‘length.tclArray’, ‘length<-.tclArray’, ‘tclObj.tclVar’, ‘tclObj<-.tclVar’, ‘tclvalue.default’, ‘tclvalue.tclObj’, ‘tclvalue.tclVar’, ‘tclvalue<-.default’, ‘tclvalue<-.tclVar’, ‘close.tkProgressBar’ were declared in NAMESPACE but not found
Error : .onLoad failed in loadNamespace() for 'tcltk', details:
  call: fun(libname, pkgname)
  error: Tcl/Tk support is not available on this system
ERROR: lazy loading failed for package ‘geoR’
* removing ‘/usr/local/lib/R/3.4/site-library/geoR’
* restoring previous ‘/usr/local/lib/R/3.4/site-library/geoR’

The downloaded source packages are in
    ‘/private/var/folders/kh/0s66cjl5487fg_fhwgxqd2340000gn/T/RtmpooD5vJ/downloaded_packages’
Warning message:
In install.packages("geoR") :
  installation of package ‘geoR’ had non-zero exit status

好吧,经过大量谷歌搜索和分析我阅读的内容后,我推导出了一个解决方案。

在这里,我添加了一些背景知识,说明为什么我需要一个解决方案以及我采用的分步过程。请注意,它肯定不是最终的 solution/procedure,也许有些步骤是多余的 - 我会把它交给其他人。

背景

有时数据非常倾斜,包含很多 'zeros'(或接近 'zero' 的非常小的数字)。在分析此类数据之前,需要对其进行归一化以满足统计检验的假设 (you can find more on transformation and normalisation here)。通常人们对数变换(例如自然对数,或对数2),缺点是你失去了'zeros'.

在我的例子中,这是一个问题,因为所做的测量是正确完成的(没有技术问题),所以 'zero' 确实代表 'zero'。换句话说:我不想丢掉它们。几年前,我的一位同事向我指出 'Box-Cox' 转换 (you can find more on that here),并且此方法可通过 [=11] 在 R 中使用=] 包.

问题是:我使用 brew 安装 R 以及 macOS 上缺少的许多其他 packages/libraries,例如 wget.由于我仍然不明白的原因 - 但我也意识到它超出了我的编码能力 - brew not 通常安装 R with tcl-tk 包。让 that 成为 geoR 所需的关键部分,并通过扩展功能 boxccoxfit 来工作。经过一些谷歌搜索后,我得到了一些提示,这些提示使我找到了(表面上)永久解决方案; the discussion on the brew website were critical.

循序渐进

  1. 我确定我已经通过 brew 安装了 tcl-tk。

    • brew install tcl-tk
    • 我确定 tcl-tk 在我的路径中:echo 'export PATH="/usr/local/opt/tcl-tk/bin:$PATH"' >> ~/.bash_profile
    • 命令wish也证实了这一点。
  2. 我还确保我已正确安装命令行工具 - 上周对 High Sierra 进行了一些更新,其他人报告了相关问题,所以我担心它可能不得不重新-安装。我不必这样做,但这是我检查的方式。命令brew config显示:

    HOMEBREW_VERSION: 1.5.2
    ORIGIN: https://github.com/Homebrew/brew
    HEAD: 60a30e966b7cece5bd4823dae3fb981ab85106ea
    Last commit: 13 days ago
    Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
    Core tap HEAD: 8c1c4f86a269cb23d9d92008abf1a37eabb297b6
    Core tap last commit: 2 days ago
    HOMEBREW_PREFIX: /usr/local
    CPU: quad-core 64-bit skylake
    Homebrew Ruby: 2.3.3 => /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby
    Clang: 9.0 build 900
    Git: 2.16.1 => /usr/local/bin/git
    Curl: 7.54.0 => /usr/bin/curl
    Perl: /usr/bin/perl
    Python: /usr/local/opt/python/libexec/bin/python => /usr/local/Cellar/python/2.7.14_2/Frameworks/Python.framework/Versions/2.7/bin/python2.7
    Ruby: /usr/bin/ruby => /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby Java: 9.0.1
    macOS: 10.13.3-x86_64
    Xcode: N/A
    ** CLT: 9.2.0.0.1.1510905681**
    X11: 2.7.11 => /opt/X11

    粗体字表示应该安装Command Line Tools

  3. 我仔细检查了路径是否真的设置,使用命令 xcode-select -p,结果显示:

    /Library/Developer/CommandLineTools


  4. 另外 gcc 设置正确。我使用 gcc --version 检查了这个,它显示:

    Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
    Apple LLVM version 9.0.0 (clang-900.0.39.2)
    Target: x86_64-apple-darwin17.4.0
    Thread model: posix
    InstalledDir: /Library/Developer/CommandLineTools/usr/bin


  5. 现在我已经确认了基础知识,我开始重新安装 XquartzRRStudio。为了确保我得到 R with tcl-tk 我使用了 @srfore 的 R 版本。这些是后续命令。

    • brew cask reinstall xquartz,重新安装 Xquartz可选,如果已安装。
    • brew reinstall -s sethrfore/homebrew-r-srf/r,安装了 R.
    • 的编辑版本
    • brew cask reinstall rstudio,重新安装 Rstudio可选,如果已安装。
  6. 一切正常,我用 brew doctor 仔细检查过。

    Your system is ready to brew.

  7. 当然,对我来说,这一切都始于需要使用 RgeoR 中的函数 boxcoxfit,它依赖于 tcl-tk。所以,现在是表演时间,我开始了 R:

    install.packages("geoR")
    Installing package into ‘/usr/local/lib/R/3.4/site-library’
    (as ‘lib’ is unspecified)
    --- Please select a CRAN mirror for use in this session ---
    Secure CRAN mirrors

    To many to show here, so I deleted this part.

    Selection: 1
    trying URL 'https://cloud.r-project.org/src/contrib/geoR_1.7-5.2.tar.gz'
    Content type 'application/x-gzip' length 421612 bytes (411 KB)
    ==================================================
    downloaded 411 KB

    * installing source package ‘geoR’ ...
    ** package ‘geoR’ successfully unpacked and MD5 sums checked
    ** libs
    clang -I/usr/local/Cellar/r/3.4.3_1/lib/R/include -DNDEBUG -I/usr/local/opt/gettext/include -I/usr/local/opt/readline/include -I/usr/local/include -fPIC -g -O2 -c geoR.c -o geoR.o
    clang -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/usr/local/Cellar/r/3.4.3_1/lib/R/lib -L/usr/local/opt/gettext/lib -L/usr/local/opt/readline/lib -L/usr/local/lib -o geoR.so geoR.o -L/usr/local/Cellar/r/3.4.3_1/lib/R/lib -lR -lintl -Wl,-framework -Wl,CoreFoundation
    installing to /usr/local/lib/R/3.4/site-library/geoR/libs
    ** R
    ** data
    *** moving datasets to lazyload DB
    ** inst
    ** preparing package for lazy loading
    ** help
    *** installing help indices
    ** building package indices
    ** testing if installed package can be loaded
    * DONE (geoR)

    The downloaded source packages are in
    ‘/private/var/folders/kh/0s66cjl5487fg_fhwgxqd2340000gn/T/RtmpHJHtGf/downloaded_packages’


    加载 `geoR` 不是问题:

    library("geoR")
    --------------------------------------------------------------
    Analysis of Geostatistical Data
    For an Introduction to geoR go to http://www.leg.ufpr.br/geoR
    geoR version 1.7-5.2 (built on 2016-05-02) is now loaded
    --------------------------------------------------------------

这不是我要提供的一个很好的解决方案,但它为我解决了问题。我在一个协作项目中,我们希望特别使用 geoR:varcov.spatial() 。由于 mac 用户的 xquartz 等问题,我们实际上最终从原始包代码中提取函数,并在单独的脚本中单独加载该函数。我们仍在论文中引用该包,但我们并未实际安装或加载 geoR。

我知道不是很好,但这似乎是最简单的。不能解决您所有的问题,但作为计划 B 可能是一个值得考虑的角度。