RStudio加载tidyverse包失败,疑似Rtools缺失求解决方案
加载tidyverse包失败的解决方案
问题详情
执行library(tidyverse)时出现包加载失败错误,具体错误信息如下:
Error: package or namespace load failed for ‘tidyverse’ in namespaceExport(ns, exports): undefined exports: pluck<-, accumulate, accumulate2, accumulate_right, array_branch, array_tree, as_mapper, as_vector, assign_in, at_depth, attr_getter, auto_browse, chuck, compact, compose, cross, cross2, cross3, cross_d, cross_df, cross_n, detect, detect_index, discard, every, flatten_df, flatten_dfc, flatten_dfr, has_element, head_while, imap, imap_chr, imap_dbl, imap_dfc, imap_dfr, imap_int, imap_lgl, imap_raw, imodify, insistently, invoke_map, invoke_map_chr, invoke_map_dbl, invoke_map_df, invoke_map_dfc, invoke_map_dfr, invoke_map_int, invoke_map_lgl, invoke_map_raw, is_numeric, is_rate, is_scalar_numeric, iwalk, keep, lift, lift_dl, lift_dv, lift_ld, lift_lv, lift_vd, lift_vl, list_along, list_merge, list_modify, lmap, lmap_at, lmap_if, map, map2, map2_chr, map2_dbl, map2_df, map2_dfc, map2_dfr, map2_int, map2_lgl, map2_raw, map_at, map_call, map_chr, map_dbl, map_depth, map_df, map_dfc, ma In addition: Warning message: S3 methods ‘as_mapper.character’, ‘as_mapper.default’, ‘as_mapper.list’, ‘as_mapper.numeric’, ‘modify.character’, ‘modify.default’, ‘modify.double’, ‘modify.integer’, ‘modify.logical’, ‘modify.pairlist’, ‘modify2.character’, ‘modify2.default’, ‘modify2.double’, ‘modify2.integer’, ‘modify2.logical’, ‘modify_at.character’, ‘modify_at.default’, ‘modify_at.double’, ‘modify_at.integer’, ‘modify_at.logical’, ‘modify_depth.default’, ‘modify_if.character’, ‘modify_if.default’, ‘modify_if.double’, ‘modify_if.integer’, ‘modify_if.logical’, ‘print.purrr_function_compose’, ‘print.purrr_function_partial’, ‘print.purrr_rate_backoff’, ‘print.purrr_rate_delay’, ‘rate_sleep.purrr_rate_backoff’, ‘rate_sleep.purrr_rate_delay’ were declared in NAMESPACE but not found
尝试重新安装tidyverse时,系统提示需要Rtools,但执行install.packages("Rtools")无法完成安装,仍提示需先安装Rtools。
解决方案
1. 手动下载并安装匹配版本的Rtools
- 先查看当前R版本:执行
version命令,找到version.string字段的版本信息(例如R version 4.4.1 (2024-06-14)) - 根据R版本选择对应Rtools:
- R 4.3.x及以上版本:安装Rtools43
- R 4.2.x版本:安装Rtools42
- 更早版本需匹配对应年份的Rtools版本
- 安装过程中务必勾选Add Rtools to system PATH选项,确保环境变量配置生效
2. 验证Rtools安装状态
打开RStudio,执行以下命令:
Sys.which("make")
若返回结果包含Rtools的安装路径,说明安装成功。
3. 重新安装tidyverse及依赖包
- 先卸载已损坏的tidyverse和核心依赖包(错误信息中的函数大多来自purrr):
remove.packages(c("tidyverse", "purrr"))
- 优先安装二进制版本的tidyverse(无需编译,规避依赖问题):
install.packages("tidyverse", type = "binary")
- 若二进制版本仍有问题,再尝试安装源码版本(需确保Rtools已正确配置):
install.packages("tidyverse", type = "source")
4. 检查并修复包依赖
执行以下命令检查依赖状态并自动修复:
install.packages("devtools") devtools::install_deps("tidyverse")
内容的提问来源于stack exchange,提问作者Elif Y
相关产品推荐
相关产品推荐

