Selecting columns in dplyr::distinct()

I am trying to pass a character variable called "col" to dplyr::distinct() to designate the column for it to use to determine distinctness. What is the correct syntax? Each of the following are problematic:

df <- df |> distinct(col, .keep_all = T) ...
... reports an error that col is not a column in df (as expected)

df <- df |> distinct(pick(col), .keep_all = T) ...
... warns that "using an external vector in selections was deprecated in tidyselect 1.1.0. Please use all_of() or any_of instead.

df <- df |> distinct(all_of(col), .keep_all = T) ...
... warns that "using all_of() outside of a selecting function was deprecated in tidyselect 1.2.0."

I agree that the pick() and all_of()'s are annoying...
what you can try that I think will work

df |> distinct(!!sym(col))

df |> distinct(.data[[col]])

This topic was automatically closed 7 days after the last reply. 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.