I am trying to use where
in my own R package. I was going to use it in the code as tidyselect::where()
but the function is not exported. For this same reason, you cannot use @importFrom tidyselect where
.
I do not want to reference it with :::
. The code will work if I simply refer to it as where()
, but then I receive a note in the checks.
Undefined global functions or variables: where
What is going on here? I assume the function works as is since it it captured as an expression in my code, and tidyeval knows how to handle it on evaluation?
Example
As an example, if you start a clean R session, the following will work (dplyr 1.0.0) without running library(dplyr)
. It clearly knows how to handle where
.
dplyr::mutate(iris, dplyr::across(where(is.numeric), ~.x + 10))
Likewise, this will also work, but I do not want to use it in a package. So I use the above, which gets flagged in devtools::check()
.
dplyr::mutate(iris, dplyr::across(tidyselect:::where(is.numeric), ~.x + 10))
Question
How do I use where
from tidyselect
in a package without it being flagged as undefined?
There is an existing workaround for this type of problem. One of the items that is exported from tidyselect
is a list of helper function called vars_select_helpers
. This includes where
, so if you do
mutate(iris, dplyr::across(tidyselect::vars_select_helpers$where(is.numeric), ~.x + 10))
You should get the same functionality without any grumbling from the check tools.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With