tidy(dataframe) is deprecated? (broom packages)


this code return

var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm = na.rm)



The above can be done without problems.

What are the criteria for deciding what to convert or not to convert?

Does it stop running if it contains factor and character?

With your first example:

> tidy(iris)
Error in var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm = na.rm) : 
  Calling var(x) on a factor x is defunct.

So the problem is the factor, and indeed the column Species that you remove is of class factor:

sapply(iris, class)
#> Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
#>    "numeric"    "numeric"    "numeric"    "numeric"     "factor" 

The reason for that behavior I think is in the warning message:

Data frame tidiers are deprecated and will be removed in an upcoming release of broom.

So you're not supposed to use broom::tidy() on data frames anymore, and that problem won't be fixed. If you just want to transform a data frame in a tibble, you can use tidyr::tibble().

If what you were interested in were the summary statistics, alternatives include base::summary() and skimr::skim() (that gives a lot more information). Or to use your own call to dplyr::summarize(), which also makes more explicit what you're trying to obtain.

1 Like

This topic was automatically closed after 45 days. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.