第一次在 Mac 上安装 RStudio。为什么我不能安装任何软件包?

Installing RStudio on Mac for the first time. Why can't I install any packages?

在 Windows PC 上工作多年后,我已经在我的 Mac 上成功安装了 RStudio。不用说,包安装是我的下一步,但每当我尝试安装包时,都会返回错误。当我尝试安装包依赖项时发生错误...为了简洁起见,我将在此示例中使用 "tibble" 包。

原谅我的新手编码本性,我每天都在学习。

我试过安装不同的软件包(这些都来自 CRAN),但每次都出现相同的结果。

编辑:分别输入 "no"、"yes" 将安装软件包。有人知道为什么我仍然收到此输出吗?如果不必一次安装一个软件包,那就太好了。谢谢!

> install.packages("tibble")
> y
> y

我期待的是安装成功的结果,但实际输出如下:

> install.packages("tibble")
also installing the dependencies ‘utf8’, ‘fansi’, ‘pillar’, ‘rlang’


  There are binary versions available but the source versions are later:
       binary source needs_compilation
utf8    1.1.3  1.1.4              TRUE
pillar  1.0.1  1.3.1             FALSE
rlang   0.1.6  0.3.4              TRUE
tibble  1.3.4  2.1.1              TRUE

Do you want to install from sources the packages which need compilation?
y/n: y
Package which is only available in source form, and may need compilation of
  C/C++/Fortran: ‘fansi’
Do you want to attempt to install these from sources?
y/n: y
installing the source packages ‘utf8’, ‘fansi’, ‘pillar’, ‘rlang’, ‘tibble’

trying URL 'https://cran.rstudio.com/src/contrib/utf8_1.1.4.tar.gz'
Content type 'application/x-gzip' length 218882 bytes (213 KB)
==================================================
downloaded 213 KB

trying URL 'https://cran.rstudio.com/src/contrib/fansi_0.4.0.tar.gz'
Content type 'application/x-gzip' length 266123 bytes (259 KB)
==================================================
downloaded 259 KB

trying URL 'https://cran.rstudio.com/src/contrib/pillar_1.3.1.tar.gz'
Content type 'application/x-gzip' length 103972 bytes (101 KB)
==================================================
downloaded 101 KB

trying URL 'https://cran.rstudio.com/src/contrib/rlang_0.3.4.tar.gz'
Content type 'application/x-gzip' length 858992 bytes (838 KB)
==================================================
downloaded 838 KB

trying URL 'https://cran.rstudio.com/src/contrib/tibble_2.1.1.tar.gz'
Content type 'application/x-gzip' length 311836 bytes (304 KB)
==================================================
downloaded 304 KB

Warning in strptime(xx, f <- "%Y-%m-%d %H:%M:%OS", tz = tz) :
  unknown timezone 'zone/tz/2018i.1.0/zoneinfo/America/New_York'
* installing *source* package ‘utf8’ ...
** package ‘utf8’ successfully unpacked and MD5 sums checked
** libs
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
ERROR: compilation failed for package ‘utf8’
* removing ‘/Library/Frameworks/R.framework/Versions/3.3/Resources/library/utf8’
Warning in install.packages :
  installation of package ‘utf8’ had non-zero exit status
Warning in strptime(xx, f <- "%Y-%m-%d %H:%M:%OS", tz = tz) :
  unknown timezone 'zone/tz/2018i.1.0/zoneinfo/America/New_York'
* installing *source* package ‘fansi’ ...
** package ‘fansi’ successfully unpacked and MD5 sums checked
** libs
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
ERROR: compilation failed for package ‘fansi’
* removing ‘/Library/Frameworks/R.framework/Versions/3.3/Resources/library/fansi’
Warning in install.packages :
  installation of package ‘fansi’ had non-zero exit status
Warning in strptime(xx, f <- "%Y-%m-%d %H:%M:%OS", tz = tz) :
  unknown timezone 'zone/tz/2018i.1.0/zoneinfo/America/New_York'
* installing *source* package ‘rlang’ ...
** package ‘rlang’ successfully unpacked and MD5 sums checked
** libs
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
ERROR: compilation failed for package ‘rlang’
* removing ‘/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rlang’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rlang’
Warning in install.packages :
  installation of package ‘rlang’ had non-zero exit status
Warning in strptime(xx, f <- "%Y-%m-%d %H:%M:%OS", tz = tz) :
  unknown timezone 'zone/tz/2018i.1.0/zoneinfo/America/New_York'
ERROR: dependencies ‘fansi’, ‘utf8’ are not available for package ‘pillar’
* removing ‘/Library/Frameworks/R.framework/Versions/3.3/Resources/library/pillar’
Warning in install.packages :
  installation of package ‘pillar’ had non-zero exit status
Warning in strptime(xx, f <- "%Y-%m-%d %H:%M:%OS", tz = tz) :
  unknown timezone 'zone/tz/2018i.1.0/zoneinfo/America/New_York'
ERROR: dependencies ‘fansi’, ‘pillar’ are not available for package ‘tibble’
* removing ‘/Library/Frameworks/R.framework/Versions/3.3/Resources/library/tibble’
Warning in install.packages :
  installation of package ‘tibble’ had non-zero exit status

The downloaded source packages are in
    ‘/private/var/folders/sn/zj2b1gqx6wsfs76h5mymrk_r0000gn/T/RtmpqBjXKW/downloaded_packages’

错误消息告诉您缺少命令行工具。他们提供从源代码编译包所需的软件(例如,C 和 C++ 编译器)。

您可以使用 xcode-select --install as described here 安装它们,或者如评论中所述,在提示从源代码编译时选择 "no"。