首页 > 解决方案 > R:在 macOS 10.15 上升级到 R 4.0 后,无法从源代码安装 R 包

问题描述

我刚刚升级到 R 4.0 并试图重新安装一些软件包。但是,我现在似乎无法从源代码安装。

例如,在询问时运行install.packages("rlang")和回答yesDo you want to install from sources the package which needs compilation? (Yes/no/cancel),我收到以下错误消息:

In file included from capture.c:1:
/Library/Frameworks/R.framework/Resources/include/Rinternals.h:39:11: fatal error: 'stdio.h' file
      not found
# include <stdio.h>
          ^~~~~~~~~
1 error generated.
make: *** [capture.o] Error 1
ERROR: compilation failed for package ‘rlang’

有人知道如何解决这个问题吗?我知道我可以只安装二进制版本,但如果不修复的话,这对于未来的软件包安装来说似乎仍然是一个烦人的问题。

非常感谢!


如果有帮助,这里是输出sessionInfo()

R version 4.0.0 (2020-04-24)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.4

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

loaded via a namespace (and not attached):
[1] compiler_4.0.0

标签: rmacosinstallation

解决方案


我还在rlangGitHub 上发布了这个问题,其中一位开发人员建议了以下修复:

  1. 创建~/.R/Makevars文件(如果还没有)
  2. 将以下行添加到~/.R/Makevars
CPPFLAGS += -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include

这似乎为我解决了这个问题。请注意,此修复仅适用于 macOS 10.15 (Catalina)

可以在此处找到有关 macOS 的 R 工具链的更多有用信息:https ://thecoatlessprofessor.com/programming/cpp/r-compiler-tools-for-rcpp-on-macos/


推荐阅读