Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

no visible binding for global variable ‘.’

I'm currently co-developing an R package using devtools. We use the tidyverse %>% and associated purrr and dplyr packages within our functions.

One of our functions is as follows (edited for clarity):

#' Print `cust_modl` object
#'
#' @param x A `cust_modl` object.
#' @param ... Additional arguments passed to `print.cust_modl()` to print the
#'   object.
#'
#' @method print cust_modl
#' @export
print.cust_modl <- function(x, ...) {

req_var_nms <- x$var %>%
purrr::compact(.x = .) %>%
names(x = .)

comp_var_ind_filt <- req_var_nms %>%
purrr::map(.x = ., .f = ~ purrr::pluck(x$var, .x))

}

This is currently giving an NOTE in our Github Actions devtools::check() as:

print.cust_modl: no visible binding for global variable ‘.’

I understand that this error is due to rlang related issues based on this helpful post. So typically we use @importFrom rlang .data as suggested and ensure that in dplyr we carry the .data$ syntax correctly when referencing columns.

However, it seems that this NOTE was being given by the purrr calls and it is not clear how to correct the rlang import for just the . (rather than the usual more explicit .data call in dplyr).

Could anyone please explain how to correctly adjust R package code for the . as called by tidyverse packages such as purrr? I understand that we can locally set . <- NULL, but is there a more rigorous way to set this using rlang? Understanding the recommended guidelines here would allow our package to be developed to community standards.

Disclaimer: This is now cross-posted from here, since it hasn't received a reply in several days.

like image 525
user4687531 Avatar asked Dec 05 '25 01:12

user4687531


1 Answers

This alert comes from the codetools package. Apart from the other solution, there is also an option of not using codetools completely in R CMD check. In your ~/.Renviron file (to quickly open from R console, use usethis::edit_r_environ()), add a line as such:

_R_CHECK_USE_CODETOOLS_= FALSE

This is recommended if you do a lot of NSE which throws many false alerts.

like image 80
Siqi Zhang Avatar answered Dec 07 '25 16:12

Siqi Zhang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!