In a function where I'm using {dplyr}, I'd like to use my function's argument in a condition inside a case_when() function.
Here's an example :
As explained here, I want to avoid an R CMD CHECK NOTE because this function is part of a package so I like to use the .data
library(dplyr)
library(rlang)
myfonction <- function(variables) {
res <- iris %>%
mutate(
newvar = case_when(
.data$paste0(variables,".Length") > 2 ~ "ok",
TRUE ~ "no"
)
)
res
}
result <- myfonction(variables="Petal")
result2 <- myfonction(variables="Sepal")
I have this error :
x Column `paste0` not found in `.data`.
Caused by error in `.data$paste0`: