Tidyverse 的 tidy() 函数在 R 中不起作用

Tidyverse's tidy() function not working in R

我有一个简单的问题,即 R 中的 tidy() 函数无法正常工作。我已经安装了 tidyverse 并加载了 library(tidyverse)。但是我收到以下错误消息:

Error in tidy(fit1b) : could not find function "tidy"

我在加载包时也遇到了以下冲突(仅“lfe”和“tidyverse”包),但我不确定是否是它们导致了问题:

x tidyr::expand() masks Matrix::expand()
x dplyr::filter() masks stats::filter()
x dplyr::lag()    masks stats::lag()
x tidyr::pack()   masks Matrix::pack()
x tidyr::unpack() masks Matrix::unpack()

您需要的函数来自 broom,不属于 tidyverse

参见:

library(tidyverse)
── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──
✔ ggplot2 3.3.2     ✔ purrr   0.3.4
✔ tibble  3.0.1     ✔ dplyr   1.0.0
✔ tidyr   1.1.0     ✔ stringr 1.4.0
✔ readr   1.3.1     ✔ forcats 0.5.0
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()

tidy(lm(mpg ~ hp,data=mtcars))
Error in tidy(lm(mpg ~ hp, data = mtcars)) : 
  could not find function "tidy"

如果加载 broom :

library(broom)
tidy(lm(mpg ~ hp,data=mtcars))
# A tibble: 2 x 5
  term        estimate std.error statistic  p.value
  <chr>          <dbl>     <dbl>     <dbl>    <dbl>
1 (Intercept)  30.1       1.63       18.4  6.64e-18
2 hp           -0.0682    0.0101     -6.74 1.79e- 7