0

Reference : Get Started With TidyModels

I can not tidy a model of class _lm to tidy. The exact code of the new tidymodel.org Get Started site is used and generates an error. My guess is that there is some package update I need.

Error: No tidy method for objects of class _lm

Here is the code as copied from the site:

library(tidymodels)
library(readr)
urchins <-
  # Data were assembled for a tutorial 
  # at https://www.flutterbys.com.au/stats/tut/tut7.5a.html
  read_csv("https://tidymodels.org/start/models/urchins.csv") %>% 
  # Change the names to be a little more verbose
  setNames(c("food_regime", "initial_volume", "width")) %>% 
  # Factors are very helpful for modeling, so we convert one column
  mutate(food_regime = factor(food_regime, levels = c("Initial", "Low", "High")))
#> Parsed with column specification:
#> cols(
#>   TREAT = col_character(),
#>   IV = col_double(),
#>   SUTW = col_double()
#> )
urchins
ggplot(urchins,
       aes(x = initial_volume, 
           y = width, 
           group = food_regime, 
           col = food_regime)) + 
  geom_point() + 
  geom_smooth(method = lm, se = FALSE) +
  scale_color_viridis_d(option = "plasma", end = .7)
lm_mod <- 
  linear_reg() %>% 
  set_engine("lm")
lm_fit <- 
  lm_mod %>% 
  fit(width ~ initial_volume * food_regime, data = urchins)
lm_fit
tidy(lm_fit)
Harlan Nelson
  • 1,394
  • 1
  • 10
  • 22

1 Answers1

2

I am surmising that you are working in R 4.0 because we have seen other users have this same problem. There was a change in lexical scoping that impacts S3 registration of methods such as the tidy method. You can check out somebody having a similar problem here.

We have fixed this problem in the dev version of parsnip and it will be submitted to CRAN ASAP. Until a new CRAN release, you can use

devtools::install_dev("parsnip")

to get the new version.

Julia Silge
  • 10,848
  • 2
  • 40
  • 48
  • Yes, I am using 4.0. and the dev dplyr as well. I am working through the entire tidymodels.org site code using my data and classification. I would run survival if that were possible. – Harlan Nelson Apr 30 '20 at 21:53