2

I am looking to find another function that can replace the broom::tidy() function after it get removed. Here is what the broom package warning says:

Tidy Atomic Vectors Vector tidiers are deprecated and will be removed from an upcoming release of broom.

Here is a description of function:

tidy() produces a tibble() where each row contains information about an important component of the model. For regression models, this often corresponds to regression coefficients. This is can be useful if you want to inspect a model or create custom visualizations.

Thanks you,

John

John E.
  • 137
  • 2
  • 10

3 Answers3

3

As I understand the warning, there is no general deprecation of the function broom::tidy, this warning only occurs when it is called with an atomic vector. In this case tibble() seems to be a slot-in replacement:

No deprecation warning for tidy() when called for a linear model:

library(broom)
fit <- lm(Volume ~ Girth + Height, trees)
tidy(fit)
## A tibble: 3 x 5
#  term        estimate std.error statistic  p.value
#  <chr>          <dbl>     <dbl>     <dbl>    <dbl>
#1 (Intercept)  -58.0       8.64      -6.71 2.75e- 7
#2 Girth          4.71      0.264     17.8  8.22e-17
#3 Height         0.339     0.130      2.61 1.45e- 2

#Deprecation warning:

tidy(1:5)
## A tibble: 5 x 1
#      x
#  <int>
#1     1
#2     2
#3     3
#4     4
#5     5
#Warning messages:
#1: 'tidy.numeric' is deprecated.
#See help("Deprecated") 
#2: `data_frame()` is deprecated as of tibble 1.1.0.
#Please use `tibble()` instead.

No warning for tibble, same output :

tibble(1:5)
## A tibble: 5 x 1
#  `1:5`
#  <int>
#1     1
#2     2
#3     3
#4     4
#5     5
Miff
  • 7,486
  • 20
  • 20
  • I want to apply the tidy function to a glm that has been trim in size (I removed the qr$qr data). Tidy needs the qr$qr in order to work when its call on a glm R object. My goal is to have a table lookup for the GLM coefficient estimate. How can I reproduce that regardless the function tidier atomic vector will be remove in future release of the broom package ? Thank you – John E. Aug 27 '20 at 03:30
  • 1
    If you've got a specific use case in mind, you'll need to create a minimal reproducible example to show the example - perhaps starting with my first example would make a clear example. – Miff Aug 27 '20 at 08:33
  • Your above example is good, if you add this line of code before tidy fit$qr$qr <- NULL – John E. Aug 27 '20 at 14:59
  • Then I don't get the warning, but an error about the dimensions, that's why I was hoping you'd add an example that demonstrates your issue – Miff Aug 27 '20 at 16:07
  • You can use the same example and output you have describe in your post and remove the qr$qr portion of your model. – John E. Aug 29 '20 at 22:38
1

The deprecation warning is letting you know that the method tidy.numeric is being removed.

broom:::tidy.numeric
function (x, ...) 
{
    .Deprecated()
    if (!is.null(names(x))) {
        dplyr::data_frame(names = names(x), x = unname(x))
    }
    else {
        dplyr::data_frame(x = x)
    }
}

You can see the call to .Deprecated there, and the rest of the function just calls data_frame. As this function is also being deprecated, tibble is the new solution. As tibble does not honour row names, if you want to save the names, you could create something similar to the above.

tidy.numeric <- function (x, ...) 
{
    if (!is.null(names(x))) {
        tibble::tibble(names = names(x), x = unname(x))
    }
    else {
        tibble::tibble(x = x)
    }
}
CSJCampbell
  • 2,025
  • 15
  • 19
  • Something I don't understand is that my program still working as usual regardless of the warning message. Can I ignore it ? – John E. Dec 17 '20 at 15:58
  • 1
    @JohnE. yes, the deprecation will occur in a future version of the package. You can continue using this in scripts for now. One day you will update the package and `broom:::tidy.numeric` will no longer exist. The maintainers may provide some other functionality so that the script still works but with a different named function, or perhaps it will raise an error. There is no guarantee that the your script will behave the same at that point. – CSJCampbell Jan 04 '21 at 15:17
0

If you try to convert a named vector as mentioned by @Miff, you can also use the function enframe(). It creates a tibble with two columns, one with the names in the vector and one column with the values.

Daniel D
  • 69
  • 4