How do I use tidyselect "where" in a custom package?

Viewed 1073

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?

1 Answers

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.

Related