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

查看:134
本文介绍了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而不是.,然后使用rlang包中的import .data.从使用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::do中有效.

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天全站免登陆