no visible binding for global variable ‘.’

use*_*531 14 r dplyr tidyeval rlang

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

\n

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

\n
#\' Print `cust_modl` object\n#\'\n#\' @param x A `cust_modl` object.\n#\' @param ... Additional arguments passed to `print.cust_modl()` to print the\n#\'   object.\n#\'\n#\' @method print cust_modl\n#\' @export\nprint.cust_modl <- function(x, ...) {\n\nreq_var_nms <- x$var %>%\npurrr::compact(.x = .) %>%\nnames(x = .)\n\ncomp_var_ind_filt <- req_var_nms %>%\npurrr::map(.x = ., .f = ~ purrr::pluck(x$var, .x))\n\n}\n
Run Code Online (Sandbox Code Playgroud)\n

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

\n
print.cust_modl: no visible binding for global variable \xe2\x80\x98.\xe2\x80\x99\n
Run Code Online (Sandbox Code Playgroud)\n

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\nthat in dplyr we carry the .data$ syntax correctly when referencing columns.

\n

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

\n

Could anyone please explain how to correctly adjust R package code for the . as called by\ntidyverse 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.

\n

免责声明:由于几天没有收到回复,因此现在从此处交叉发布。

\n

小智 6

此警报来自codetools包。codetools除了其他解决方案之外,在 R CMD 检查中还有一个不完全使用的选项。在您的~/.Renviron文件中(要从 R 控制台快速打开,请使用usethis::edit_r_environ()),添加一行,如下所示:

_R_CHECK_USE_CODETOOLS_= FALSE
Run Code Online (Sandbox Code Playgroud)

如果您进行大量 NSE 并引发许多错误警报,则建议您这样做。

  • 关闭此功能会阻止未声明变量的有效警告,尽管这是正确的吗?例如,您不会收到引用全局变量的警告 (3认同)