加载 tidyverse 库时遇到问题

问题描述 投票:0回答: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 "%>%"
> 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"

使用 RTools 4.2 的 R Studio 2022.12.15 中的 R-4.2.2 存在大量错误。我刚刚尝试重新安装,但出现以下错误:

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
,或更换管道操作员)。我认为最终替换管道操作符是有效的,但是其他术语无法识别,就好像未安装
tidyverse
一样。

这一定是我反复做错的一些基本事情。我在安装

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()
r tidyverse install.packages stringi
2个回答
0
投票

根据评论中的建议,我安装了

stringi
软件包,一旦我重新启动计算机并重新运行我的脚本,它就完全起作用了。


0
投票

在每行代码后单击 Windows 上的 Ctrl+Enter 可逐行运行脚本。 记得先保存文件 因为代码没有错误

© www.soinside.com 2019 - 2024. All rights reserved.