You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

macOS下RStudio安装tidyverse包失败,加载报错求助

无法安装tidyverse:依赖版本不兼容问题解决

环境信息

  • RStudio版本:2022.07.0+548 "Spotted Wakerobin" Release (34ea3031089fa4e38738a9256d6fa6d70629c822, 2022-07-06) for macOS
  • 浏览器信息:Mozilla/5.0 (Macintosh; Intel Mac OS X 12_4_0) AppleWebKit/537.36 (KHTML, like Gecko) QtWebEngine/5.12.10 Chrome/69.0.3497.128 Safari/537.36

问题现象

执行install.packages("tidyverse")时的输出如下:

also installing the dependencies ‘cli’, ‘dplyr’, ‘vctrs’, ‘dbplyr’
 There are binary versions available but the source versions are later:
          binary source needs_compilation cli        3.2.0  3.3.0              TRUE dplyr      1.0.8  1.0.9              TRUE vctrs      0.4.0  0.4.1 TRUE dbplyr     2.1.1  2.2.1             FALSE tidyverse  1.3.1  1.3.2 FALSE

Do you want to install from sources the packages which need compilation? (Yes/no/cancel) no trying URL 'https://mirror.rcg.sfu.ca/mirror/CRAN/bin/macosx/contrib/4.0/cli_3.2.0.tgz' Content type 'application/octet-stream' length 1151378 bytes (1.1 MB)
================================================== downloaded 1.1 MB

trying URL 'https://mirror.rcg.sfu.ca/mirror/CRAN/bin/macosx/contrib/4.0/dplyr_1.0.8.tgz' Content type 'application/octet-stream' length 1296204 bytes (1.2 MB)
================================================== downloaded 1.2 MB

trying URL 'https://mirror.rcg.sfu.ca/mirror/CRAN/bin/macosx/contrib/4.0/vctrs_0.4.0.tgz' Content type 'application/octet-stream' length 1729317 bytes (1.6 MB)
================================================== downloaded 1.6 MB


The downloaded binary packages are in   /var/folders/f6/_7s3zhw96r708r9tg_1kgzl80000gn/T//RtmpaUCrbe/downloaded_packages installing the source packages ‘dbplyr’, ‘tidyverse’

trying URL 'https://mirror.rcg.sfu.ca/mirror/CRAN/src/contrib/dbplyr_2.2.1.tar.gz' Content type 'application/octet-stream' length 670569 bytes (654 KB)
================================================== downloaded 654 KB

trying URL 'https://mirror.rcg.sfu.ca/mirror/CRAN/src/contrib/tidyverse_1.3.2.tar.gz' Content type 'application/octet-stream' length 702514 bytes (686 KB)
================================================== downloaded 686 KB

* installing *source* package ‘dbplyr’ ...
** package ‘dbplyr’ successfully unpacked and MD5 sums checked
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) :    namespace ‘cli’ 3.2.0 is already loaded, but >= 3.3.0 is required Calls: <Anonymous> ... namespaceImportFrom -> asNamespace -> loadNamespace Execution halted ERROR: lazy loading failed for package ‘dbplyr’
* removing ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/dbplyr’ Warning in install.packages :   installation of package ‘dbplyr’ had non-zero exit status ERROR: dependency ‘dbplyr’ is not available for package ‘tidyverse’
* removing ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/tidyverse’ Warning in install.packages :   installation of package ‘tidyverse’ had non-zero exit status

The downloaded source packages are in   ‘/private/var/folders/f6/_7s3zhw96r708r9tg_1kgzl80000gn/T/RtmpaUCrbe/downloaded_packages’

安装完成后执行library("tidyverse")报错:

Error in library(tidyverse) : there is no package called ‘tidyverse’

已尝试的方法:

  • 卸载并重装RStudio
  • 确认安装的是最新版本
  • 更换CRAN镜像(已换回默认镜像)

解决方案

核心原因

dbplyr 2.2.1要求cli版本至少为3.3.0,但你选择安装二进制包时仅获取了cli 3.2.0,导致编译dbplyr源码包时版本不兼容,最终dbplyr安装失败,依赖它的tidyverse也无法完成安装。

步骤1:更新cli到满足要求的版本

  1. 关闭所有R会话,重新打开干净的RStudio(确保没有加载任何包)
  2. 执行以下命令安装cli的最新版本:
    # 若允许编译(需先安装Xcode命令行工具:xcode-select --install)
    install.packages("cli", type = "source")
    # 若要优先二进制包,可先检查是否有对应R版本的cli 3.3.0二进制包,若无则需安装编译工具
    

步骤2:安装dbplyr

在cli版本达标后,安装dbplyr:

install.packages("dbplyr")

步骤3:安装tidyverse

最后安装tidyverse:

install.packages("tidyverse")

备选方案:一次性安装所有依赖

如果上述步骤仍有问题,可尝试直接安装源码包(需编译工具):

install.packages("tidyverse", type = "source", dependencies = TRUE)

额外建议

  • 建议升级R版本到4.2及以上,这样能获取更多最新包的二进制版本,减少编译需求
  • 若安装编译工具时遇到问题,可在终端执行gcc --version确认是否正常工作

内容的提问来源于stack exchange,提问作者Christophe

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.26 03:16:07