I have started to recieve a warning when using selecting functions within tidyverse
packages.
Example:
library(dplyr)
set.seed(123)
df = data.frame(
"id" = c(rep("G1", 3), rep("G2", 4), rep("G3", 3)),
"total" = sample.int(n = 10),
"C1" = sample.int(n=10),
"C2" = sample.int(n=10),
"C3" = sample.int(n=10))
cols.to.sum = c("C1", "C2")
df.selected = df %>%
dplyr::select(total, cols.to.sum)
Giving:
Note: Using an external vector in selections is ambiguous.
i Use `all_of(cols.to.sum)` instead of `cols.to.sum` to silence this message.
i See <https://tidyselect.r-lib.org/reference/faq-external-vector.html>.
This message is displayed once per session.
It does not warning if I refactor to:
df.selected = df %>%
dplyr::select(total, all_of(cols.to.sum))
This behaviour has changed from tidyselect_0.2.5
to tidyselect_1.0.0
. There was no warning untill now.
On documentation about this change (https://tidyselect.r-lib.org/reference/faq-external-vector.html) it is stated that this is just a warning but it will turn into an error in the future.
My question here is how to deal such a change regarding the existing code.
Should I refactor every single line of code that uses this selection method to add the all_of()
to external vector reference? That sounds something hard to accomplish when there might be hundreds of pieces in code where a selection has been made this way (it also affects to other functions such as
summarise_at
for example).
Would the only alternative be to stick to tidyselect_0.2.5
to keep running code working?
What is the way to go on changes like this in a package regarding the existing code?
Thanks