Skip to content

tidyselect Warning when using pivot_wider with a variable for column name #1581

Closed as not planned
@martinmodrak

Description

@martinmodrak

Some of the code in tidyr seems to not have been updated to reflect tidyselect 1.1.0 requirement to use all_of / any_of. This results in unnecessary warnings, but for some reason only when column names are passed as variables.

df <- data.frame(id = 1:40, a = rep(LETTERS[1:2], each = 20), val = rnorm(40))
#No warning
pivot_wider(df, names_from = "a", values_from = "val")

varname <- "val"
# Warning
pivot_wider(df, names_from = "a", values_from = varname)

The warning produced is

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(varname)

  # Now:
  data %>% select(all_of(varname))

See <https://tidyselect.r-lib.org/reference/faq-external-vector.html>.
This warning is displayed once every 8 hours.
Call `lifecycle::last_lifecycle_warnings()` to see where this warning was generated.

Note: reprex requires a fresh session as the warning is not repeated on subsequent runs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions