Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export where() #201

Closed
markfairbanks opened this issue May 17, 2020 · 23 comments · Fixed by #274
Closed

Export where() #201

markfairbanks opened this issue May 17, 2020 · 23 comments · Fixed by #274
Assignees
Milestone

Comments

@markfairbanks
Copy link

markfairbanks commented May 17, 2020

I was trying to reexport where() for my package that uses tidyselect, but the function isn't currently exported in v1.1.0.

library(tidyselect)

tidyselect::where
#> Error: 'where' is not an exported object from 'namespace:tidyselect'
@lionel-
Copy link
Member

lionel- commented May 18, 2020

This is on purpose, for now.

@markfairbanks
Copy link
Author

markfairbanks commented May 18, 2020

Ah gotcha. Is there a reason for this?

I currently have functions that have defaults like cols = where(is.character) that throw warnings using devtools::check(). Using the bare form cols = is.character is also flagged due to the warnings tidyselect generates.

@lionel-
Copy link
Member

lionel- commented May 18, 2020

Just hesitance regarding using up a good function name. I think we'll end up exporting it anyway, since it'd probably be confusing to have different functionality for the same symbol. R CMD check note is a good point (altough easy to work around).

@CorradoLanera
Copy link

devtools::check() signals both usages:

E.g., assume it is used inside a dplyr::select() call as:

  • tidyselect::where(<something>): NOTE: Missing or unexported object: ‘tidyselect::where’
  • where(<something>): NOTE: no visible global function definition for ‘where’

How should we use {dplyr} & co. into a package using where and passing the checks? Should we Import {tidyselect}, or not?

@lionel-
Copy link
Member

lionel- commented Jun 27, 2020

utils::globalVariables("where") for now.

@williamlief
Copy link

I just ran into the same issue with re-exporting tidyselect::where in my package. It would be nice if a note could be added to the documentation for where about this issue (my apologies if such a note does exist in the documentation and I just did not see it).

@lhmet
Copy link

lhmet commented Aug 18, 2020

I managed to make it work by doing:

  1. Ensuring that the {tidyselect} dependency has been added to DESCRIPTION: usethis::use_package ("tidyselect")

  2. Calling it using tidyselect::vars_select_helpers$where and importing it using
    #' @importFrom tidyselect vars_select_helpers

lhmet added a commit to lhmet-ped/HEobs that referenced this issue Aug 19, 2020
It was missing add tidyselect.
@lionel-
Copy link
Member

lionel- commented Aug 19, 2020

@lhmet I would really recommend this instead:

utils::globalVariables("where")

globalVariables() is often the right and correct answer to static analysis problems with NSE functions.

@sclewis23
Copy link

Any idea when you will export where?

@lionel-
Copy link
Member

lionel- commented Aug 21, 2020

Probably in the next version, but that's not high priority because the workaround is easy and non-invasive.

@lionel- lionel- mentioned this issue Aug 26, 2020
@NateNohling
Copy link

Writing my first package and still struggling with where() even after reading this thread.

I added this line into the function to define where, and then later call where(!is.list) in the function and it passes the CMD check fine.
where <- utils::globalVariables("where")

But when I run the package, I get an error.

Error in registerNames(names, package, ".global", add) :
The namespace for package "functions" is locked; no changes in the global variables list may be made.

Any ideas or updates on when we can just put tidyselect::where() into packages?

@lionel-
Copy link
Member

lionel- commented Jan 12, 2021

Hello. You shouldn't assign where. Change this:

 where <- utils::globalVariables("where")

Into:

utils::globalVariables("where")

I don't know why you're getting this error message though. Where did you put the globalVariables() call? And what do you mean by "run the package"?

@petrbouchal
Copy link

@NateNohling @lionel- I ran into the same error because I put utils::globalVariables("where") inside a function definition - it needs to go outside. Apparently this is mentioned somewhere in the help page but I also had a hard time finding out where to put the call. See https://stackoverflow.com/questions/40251801/how-to-use-utilsglobalvariables.

@NateNohling
Copy link

@petrbouchal Ah...got it! That fixed it! Thanks

@evanmascitti
Copy link

How does one actually call this function inside a package once it is OK'd with utils::globalVariables() ? If using no accessor, I receive the message "can't find function where(). If I use ::: I still get a note from R CMD CHECK saying the ::: operator is frowned upon.

@lionel-
Copy link
Member

lionel- commented Apr 20, 2021

where() is not meant to be evaluated by the R interpreter, only by the tidyselect interpreter. Selections are a DSL on top of R. (Unlike data-masking which is pure R)

@dkgaraujo
Copy link

Just coming here to add to the call for exporting where 😀.

@ramiromagno
Copy link

Idem.

@peterjuv
Copy link

Idem :)

@SimonDedman
Copy link

SimonDedman commented Dec 16, 2021

So per @petrbouchal 's link: add
#' @import utils
to the function param block, and
utils::globalVariables("where")
within the function script.

Edit: this didn't actually fix it. So if anyone knows how to do so, please say. I'm still getting:

Error in registerNames(names, package, ".global", add) :
The namespace for package "gbm.auto" is locked; no changes in the global variables list may be made.

(gbm.auto is my package name)

idem / +1 / samesies for exporting please. Cheers!

Edit2: Spacedman & DHW note that the utils::globalVariables("where") line has to be outside/under the function definition, which I understand to mean:

f <- function(params){
code
}
HERE

but that doesn't work for me either.

@lionel-
Copy link
Member

lionel- commented Mar 3, 2022

It is likely that where() will be superseded in favour of anonymous functions, see #248.

@jjesusfilho
Copy link

jjesusfilho commented Apr 4, 2022

It is likely that where() will be superseded in favour of anonymous functions, see #248.

I haven't been able to replace where() with an anonymous function in this case:

 df <- tibble::tibble(a = c(NA, NA, NA),
                       b = c(NA, 3,4),
                       c = c(NA, 5,6))

df <- df |> 
  dplyr::select(!where(~all(is.na(.x))))

@paladinic
Copy link

paladinic commented Apr 28, 2022

@jjesusfilho would discard() work?
example found here

eroten added a commit to Metropolitan-Council/travel-study-stories that referenced this issue Jun 28, 2022
eroten added a commit to Metropolitan-Council/travel-study-stories that referenced this issue Aug 5, 2022
@lionel- lionel- added this to the next milestone Aug 10, 2022
hadley added a commit that referenced this issue Aug 10, 2022
@hadley hadley mentioned this issue Aug 10, 2022
hadley added a commit that referenced this issue Aug 10, 2022
@hadley hadley unpinned this issue Aug 11, 2022
gartician added a commit to maxsonBraunLab/CITEViz that referenced this issue Oct 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.