0

I changed the name of my github package by removing an illegal underscore and it's caused everything to break. I've subsequently removed all except the 5 core scripts from /R/ but still can't get it to install.

The current problem is, when I document() I get

Error in filter(check1, relocations >= bbdwindowsize): object 'relocations' not found

From here:

check1 <- data %>%
    group_by(ID) %>%
    summarise(relocations = length(Datetime))
check2 <- filter(check1, relocations >= bbdwindowsize)

There's nothing wrong with this code. Does document() not understand dplyr coding style?

Thanks

Edit: Thanks for the quick replies folks. Per MrFlick's suggestion:

# at top
#' @importFrom rlang .data
# then:
check1 <- data %>%
    group_by(.data$ID) %>%
    summarise(relocations = length(.data$Datetime))
check2 <- filter(check1, .data$relocations >= bbdwindowsize)

Error in (check2 line): Can't subset .data outside of a data mask context.

Any ideas? Thanks again.

dez93_2000
  • 1,730
  • 2
  • 23
  • 34
  • 1
    See the "Eliminating R CMD check NOTEs" section of the [programming with dplyr guide](https://cran.r-project.org/web/packages/dplyr/vignettes/programming.html) – MrFlick Apr 01 '22 at 16:40
  • 1
    did you call `library(dplyr)` in that script? if not it might be trying to use `filter()` from the stats package – Mike Apr 01 '22 at 16:40
  • Thanks Flick, just tried that & updated question. Thanks Mike, not exactly, `#' @import dplyr` at the top instead – dez93_2000 Apr 01 '22 at 17:11
  • 1
    Is your code outside of a function? Is this supposed to be part of an "example" section? It does seem like the wrong `filter()` is being called but it's unclear exactly how your package code is organized,. – MrFlick Apr 01 '22 at 19:59
  • Thanks. I slapped `dplyr::` in front of everything around that area and that solved it (/ kicked the can down the road to the next issue with `document`) – dez93_2000 Apr 01 '22 at 22:07
  • @MrFlick if you want credit for the answer by all means put your comment as a proper answer and I'll tick it. Thanks – dez93_2000 Apr 04 '22 at 14:43

1 Answers1

2

No Rcheck doesn't understand.

One way to deal with that is to create fake global variables

globalVariables(c("relocations", [everything other symbol you used]))

in the package.R file of your package.

It had been advised by Hadley Wickham in the past ( How can I handle R CMD check "no visible binding for global variable" notes when my ggplot2 syntax is sensible? ) and still passes RCheck

Through, the tidyverse tutorials nowaday recommend to import rlang::.data cf https://ggplot2.tidyverse.org/articles/ggplot2-in-packages.html or https://dplyr.tidyverse.org/articles/programming.html .

Arnaud Feldmann
  • 761
  • 5
  • 17
  • 1
    Rather than create fake global variables, the current recommendation is to use the `.data` pronoun instead. – MrFlick Apr 01 '22 at 16:42
  • 1
    I had seen some recommandation by Hadley Wickham once but maybe things changed – Arnaud Feldmann Apr 01 '22 at 16:44
  • 1
    Well, if you have a reference feel free to include it, but that sounds outdated at least according to the current [programming with dplyr guide](https://cran.r-project.org/web/packages/dplyr/vignettes/programming.html) – MrFlick Apr 01 '22 at 16:46
  • 1
    https://stackoverflow.com/questions/9439256/how-can-i-handle-r-cmd-check-no-visible-binding-for-global-variable-notes-when Found – Arnaud Feldmann Apr 01 '22 at 16:48
  • 1
    A lot has changed since 2012. That was well before the `.data` pronoun existed. It would be better to follow the current best practices. Other answers in that thread are more up-to-date, ie https://stackoverflow.com/a/57496617/2372064 – MrFlick Apr 01 '22 at 16:50
  • 1
    Thanks @MrFlick . You're right that it's better to follow the evolution of the best practices. However does your trick work if you want to keep the tidyverse as suggests, nor depends ? – Arnaud Feldmann Apr 01 '22 at 16:59
  • 1
    Well if you are trying to use `dplyr` commands, then you'll have a dependency on `dplyr` so you'll have access to `.data`. But I don't immediately see why just using suggests would be a problem. You could just use `dplyr::.data` when you need to. – MrFlick Apr 01 '22 at 17:02
  • 1
    Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/243531/discussion-between-arnaud-feldmann-and-mrflick). – Arnaud Feldmann Apr 01 '22 at 17:10