R软件包的安装/编译错误:tidyverse和插入符号



我最近不得不在一本新的Macbook上安装RStudio和R语言。它似乎可以正常安装软件包,但当我开始运行一些新编写的代码时,控制台不会执行tidyverse和caret,即使它说它已经下载了。这就是控制台中显示的内容,对于插入符号和tidyverse都是相同的消息:

> install.packages("tidyverse")
trying URL 'https://cran.rstudio.com/bin/macosx/contrib/4.1/tidyverse_1.3.1.tgz'
Content type 'application/x-gzip' length 421072 bytes (411 KB)
==================================================
downloaded 411 KB

The downloaded binary packages are in
/var/folders/pl/w9k_0l4d4snfgcv53rp2t_4m0000gn/T//RtmpWScbjK/downloaded_packages
> library(tidyverse)
Error: package or namespace load failed for ‘tidyverse’ in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]):
there is no package called ‘Rcpp’

我甚至试着只在R上安装它,而不是在RStudio上安装它。这是当我试着在R和RStudio:上同时安装Rcpp时,tidyverse和caret都会出现的消息

> install.packages("Rcpp")
There is a binary version available but the source version is later:
binary  source needs_compilation
Rcpp 1.0.8.2 1.0.8.3              TRUE
Do you want to install from sources the package which needs compilation? (Yes/no/cancel) yes
installing the source package ‘Rcpp’
trying URL 'https://cloud.r-project.org/src/contrib/Rcpp_1.0.8.3.tar.gz'
Content type 'application/x-gzip' length 3086192 bytes (2.9 MB)
==================================================
downloaded 2.9 MB
* installing *source* package ‘Rcpp’ ...
** package ‘Rcpp’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
ERROR: compilation failed for package ‘Rcpp’
* removing ‘/Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp’
The downloaded source packages are in
‘/private/var/folders/pl/w9k_0l4d4snfgcv53rp2t_4m0000gn/T/Rtmp53AysU/downloaded_packages’
Warning message:
In install.packages("Rcpp") :
installation of package ‘Rcpp’ had non-zero exit status

我不确定出了什么问题,我在这里或其他网站上也没有看到任何对我有用的解决方案,我很感激任何帮助,因为我经常使用R。如果需要更多信息,请评论,谢谢。

可能需要重新安装rlang软件包。您可以使用此代码重新安装此软件包:

remove.packages("rlang")
install.packages("rlang")

之后,您可以再次加载包tidyversecaret

library(tidyverse)
library(caret)

请检查此问题以获取更多信息:错误:loadNamespace 中"tidyverse"的包或命名空间加载失败

最新更新