加载tidyverse库遇问题:R-4.2.2与RStudio环境报错求助
Tidyverse加载与函数调用故障排查
环境配置
- R版本:4.2.2
- RStudio版本:2022.12.15
- RTools版本:4.2
故障现象
代码执行报错
执行以下代码:
install.packages("dslabs") install.packages("tidyverse") library(dslabs) library(tidyverse) data(murders) murders %>% ggplot(aes(population, total, label=abb, color=region)) + geom_label()
出现报错:
Error in murders %>% ggplot(aes(population, total, label = abb, color = region)) :
could not find function "%>%"
替换为R原生管道运算符|>后执行:
murders |> ggplot(aes(population, total, label=abb, color=region)) + geom_label()
仍报错:
Error in ggplot(murders, aes(population, total, label = abb, color = region)) :
could not find function "ggplot"
重装tidyverse时的依赖错误
重装tidyverse包时,提示:
Error: package or namespace load failed for ‘tidyverse’ in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]): there is no package called ‘stringi’
已尝试的解决方案
- 安装并单独加载
magrittr、dplyr包 - 替换管道运算符为R原生的
|> - 手动安装
stringi包并重启R环境
当前状态
安装stringi后,加载tidyverse时显示所有子包已正常附加:
> library(tidyverse) ── Attaching packages ─────────────────────────────── tidyverse 1.3.2 ── ✔ ggplot2 3.4.0 ✔ purrr 1.0.1 ✔ tibble 3.1.8 ✔ dplyr 1.0.10 ✔ tidyr 1.2.1 ✔ stringr 1.5.0 ✔ readr 2.1.3 ✔ forcats 0.5.2 ── Conflicts ────────────────────────────────── tidyverse_conflicts() ── ✖ dplyr::filter() masks stats::filter() ✖ dplyr::lag() masks stats::lag()
但函数未被识别的问题仍需排查根源与解决方法。
内容的提问来源于stack exchange,提问作者Julie McMinn
相关产品推荐
相关产品推荐

