R devtools document error: object not found, but created in pipe by summarise()

307 Views Asked by At

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.

1

There are 1 best solutions below

8
On

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 .