When I run devtools::check() for my package I get the following notes:
❯ checking R code for possible problems ... NOTE
IMPosterior: no visible binding for global variable ‘section’
IMPosterior: no visible binding for global variable ‘y’
IMPosterior: no visible binding for global variable ‘prob’
Undefined global functions or variables:
prob section y
How can I solve that? I believe this is the code that generates the problem:
# Calculate density values for input data
dens <- data.frame(stats::density(x, n=2^10, adjust=1)[c("x","y")]) %>%
dplyr::mutate(section = cut(x, breaks=breaks)) %>%
dplyr::group_by(section) %>%
dplyr::mutate(prob = paste0(round(sum(y)*mean(diff(x))*100),"%"))
I see this has been solved but here is a dplyr/rlang specific suggestion: you can use the .data pronoun cf this dplyr vignette,
"If this function is in a package, using .data also prevents R CMD check from giving a NOTE about undefined global variables (provided that you’ve also imported rlang::.data with @importFrom rlang .data )."