dplyr .和 _no 可见绑定全局变量 '.'_ 包检查中的注释 [英] dplyr . and _no visible binding for global variable '.'_ Note in package check

查看:20
本文介绍了dplyr .和 _no 可见绑定全局变量 '.'_ 包检查中的注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

dplyr 中可以编写代码,例如使用 '.'引用管道中的数据

In dplyr one can write code like e.g. using the '.' to refer to the data in the pipe

x <- data.frame(x = 2:4)
y <- data.frame(y = 1:3)

y %>% dplyr::bind_cols(x,.)

但是当在函数中使用它并运行包检查时它会产生

but when using it in a function and running the package check it produces the

全局变量'.'没有可见的绑定.

no visible binding for global variable '.'.

处理 NOTE 的最佳做法是什么?

What is the best practice to handle the NOTE?

推荐答案

看来最好的做法是使用 .data 而不是 . 然后使用 import .data 来自 rlang 包.来自 使用 dplyr 小插图 编程:

It seems that best practice is to use .data instead of . and then use import .data from the rlang package. From the programming with dplyr vignette:

如果此函数在包中,使用 .data 还可以防止 R CMD 检查给出有关未定义全局变量的注释(前提是您还使用 @importFrom rlang .data 导入了 rlang::.data).

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).

不幸的是,这不适用于 dplyr::bind_cols 的原始问题,但它适用于例如 dplyr::mutatedplyr::做.

Unfortunately that doesn't work for the original question with dplyr::bind_cols, but it works for example in dplyr::mutate and dplyr::do.

这篇关于dplyr .和 _no 可见绑定全局变量 '.'_ 包检查中的注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆