尝试在 MacOS 上的 R 中安装 devtools 时的非零退出状态

Non-zero exit status when attempting to install devtools in R on MacOS

我一直在尝试在 MacOS 上的 R 中安装 devtools,首先是在 RStudio 中使用:

install.packages("devtools")

然后作为替代使用:

install.packages("devtools",lib="/usr/local/Cellar/r/3.6.0_3/lib/R/library")

这导致权限错误,因此我使用了终端:

sudo R

然后使用与 RStudio 中相同的命令来安装包,这两个命令都出现以下错误:

1: In install.packages("devtools", lib = "/usr/local/Cellar/r/3.6.0_3/lib/R/library") :
  installation of package ‘xml2’ had non-zero exit status

2: In install.packages("devtools", lib = "/usr/local/Cellar/r/3.6.0_3/lib/R/library") :
  installation of package ‘roxygen2’ had non-zero exit status

3: In install.packages("devtools", lib = "/usr/local/Cellar/r/3.6.0_3/lib/R/library") :
  installation of package ‘devtools’ had non-zero exit status

我没有使用R的经验,使用Ubunu或CentOS时网上提到的解决方案都不行。

如果您对如何安装 devtools 以及导致这些错误的原因有任何建议,请告诉我,非常感谢任何建议。 提前致谢!

使用 dependencies=TRUE 进行了更多的安装,但仍然给出以下结果:

The downloaded source packages are in
    ‘/private/tmp/RtmptCt93z/downloaded_packages’
Warning messages:
1: In install.packages("devtools", dependencies = TRUE) :
  installation of package ‘xml2’ had non-zero exit status

2: In install.packages("devtools", dependencies = TRUE) :
  installation of package ‘RCurl’ had non-zero exit status

3: In install.packages("devtools", dependencies = TRUE) :
  installation of package ‘rvest’ had non-zero exit status

4: In install.packages("devtools", dependencies = TRUE) :
  installation of package ‘roxygen2’ had non-zero exit status

5: In install.packages("devtools", dependencies = TRUE) :
  installation of package ‘rversions’ had non-zero exit status

6: In install.packages("devtools", dependencies = TRUE) :
  installation of package ‘spelling’ had non-zero exit status

7: In install.packages("devtools", dependencies = TRUE) :
  installation of package ‘rsconnect’ had non-zero exit status

8: In install.packages("devtools", dependencies = TRUE) :
  installation of package ‘foghorn’ had non-zero exit status

9: In install.packages("devtools", dependencies = TRUE) :
  installation of package ‘devtools’ had non-zero exit status

10: In install.packages("devtools", dependencies = TRUE) :
  installation of package ‘pkgdown’ had non-zero exit status

我尝试手动将 RStudio 中显示的路径添加到我的 .bash_profile,这导致我的终端不再知道任何命令(sudo、nano 等),哪种方式才是正确的这,也许是 R 的路径问题?

> R.home()
[1] "/usr/local/Cellar/r/3.6.0_3/lib/R"

我终于通过 https://cran.r-project.org/web/packages/devtools/devtools.pdf 直接下载 devtools 解决了这个问题(按照@NelsonGon 的建议)

然后将该文件夹移动到 R.home()/library

然后 运行 devtools 在终端中使用 sudo 安装 github 包。