I am currently developing a package in which I try to implement a function that internally uses dplyr::group_by
. However, upon package checking (devtools CRAN checks), I get a NOTE stating that no visible binding for global variable Levels
.
foo <- function(x) {
out <- data.frame(Levels = x) %>%
group_by(Levels) %>%
summarise(n = n())
return(out)
}
foo: no visible binding for global variable 'Levels'
Undefined global functions or variables:
Levels
In order to do it in a non-NSE fashion, I could use group_by_()
with a string, but I understood that this way of doing this is deprecated, in favour of the use of quosures. However, I still have trouble figuring out how to do it.
I tried using one_of()
, without success:
foo <- function(x) {
table_full <- data.frame(Levels = x) %>%
group_by(one_of("Levels")) %>%
summarise(n = n())
}
Error in mutate_impl(.data, dots) :
Evaluation error: No tidyselect variables were registered
What would be the most correct way of achieving that?