larmarange / broom.helpers

A set of functions to facilitate manipulation of tibbles produced by broom
https://larmarange.github.io/broom.helpers/
GNU General Public License v3.0
21 stars 8 forks source link

deprecated behavior of .select_to_varnames() #217

Closed dereksonderegger closed 1 year ago

dereksonderegger commented 1 year ago

If the user inputs a character string variable instead the quoted or unquoted string, a deprecation warning is thrown.

# make sure the deprecation warning is always thrown, by default it is only
# thrown once every eight hours.
rlang::local_options(lifecycle_verbosity = "error")

# These work just fine
broom.helpers::.select_to_varnames('Species', iris)
broom.helpers::.select_to_varnames(Species, iris)

# But this is no longer acceptable
var_string = 'Species'
broom.helpers::.select_to_varnames(var_string, iris)

When running this code, the following is produced:

rlang::local_options(lifecycle_verbosity = "error")
broom.helpers::.select_to_varnames('Species', iris)
#> [1] "Species"
broom.helpers::.select_to_varnames(Species, iris)
#> [1] "Species"

var_string = 'Species'
broom.helpers::.select_to_varnames(var_string, iris)
#> Warning: Using an external vector in selections was deprecated in tidyselect 1.1.0.
#> ℹ Please use `all_of()` or `any_of()` instead.
#>   # Was:
#>   data %>% select(var_string)
#> 
#>   # Now:
#>   data %>% select(all_of(var_string))
#> 
#> See <https://tidyselect.r-lib.org/reference/faq-external-vector.html>.
#> [1] "Species"
Created on 2023-02-23 with [reprex v2.0.2](https://reprex.tidyverse.org/)

Currently this affects Daniel Sjoberg's gtsummary package, which calls this function. This is only an issue for me when testing my package which utilizes gtsummary and this warning shows up many times during the testthat execution. I'm working on a simple example for submitting an issue to gtsummary as well, but likely he'll end up here

ddsjoberg commented 1 year ago

Hi @dereksonderegger ,

That note comes from the tidyverse. You should follow the recommendation and the note will go away, eg all_of(var_string)

dereksonderegger commented 1 year ago

As I was building an example for gtsummary(), I was surprised that the all_of() function worked here:

rlang::local_options(lifecycle_verbosity = "warning")
var_string = 'Species'
iris |>
  gtsummary::tbl_summary(by=var_string)

iris |>
  gtsummary::tbl_summary(by=all_of(var_string) )

I'm shocked that this works, because all_of() normally only works inside tidyselect functions, but I guess it gets passed through to where it actually gets evaluated, which is inside a tidyselect situation. So this actually isn't a problem because I can solve the issue with an all_of() in my code even though it gets evaluated much deeper in the code stack.

Awesome. I'm sorry to have drug you through this issue when I should have tried that.