R CMD检查中的全局变量注释没有可见的绑定 [英] No visible binding for global variable Note in R CMD check

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

问题描述

我在检查一个包时注意到,当我使用像 subset 这样的函数时,我得到注释全局变量没有可见的绑定",这些函数使用列表元素的逐字名称作为参数.

I noticed in checking a package that I obtain notes "no visible binding for global variable" when I use functions like subset that use verbatim names of list elements as arguments.

以数据框为例:

foo <- data.frame(a=c(TRUE,FALSE,TRUE),b=1:3)

foo <- data.frame(a=c(TRUE,FALSE,TRUE),b=1:3)

我可以做一些愚蠢的事情,比如:

I can do silly things like:

subset(foo,a)
transform(foo,a=b)

按预期工作.然而,R CMD 中的 R 代码检查不理解这些引用元素并抱怨没有任何可见的全局变量绑定.

Which work as expected. The R code check in R CMD however doesn't understand that these refer to elements and complains about there not being any visible bindings of global variables.

虽然这可以正常工作,但我真的不喜欢在我的包裹中有注释,而是希望它通过检查,完全没有错误、警告和注释.我也不想过多地修改我的代码.有没有办法编写这些代码,以明确参数不引用全局变量?

While this works ok, I don't really like having notes in my package and prefer for it to pass the check with no errors, warnings and notes at all. I also don't really want to rework my code too much. Is there a way to write these codes so that it is clear the arguments do not refer to global variables?

推荐答案

要通过 R CMD 检查,您可以:

  • 使用 get("b") (但这很麻烦)
  • a=b=NULL 放在函数中更高的位置(我就是这样做的)
  • Use get("b") (but that is onerous)
  • Place a=b=NULL somewhere higher up in your function (that's what I do)

前段时间在 r-devel 上有一个帖子,来自 r-core 的某个人基本上说(从记忆中)NOTES 没问题,你知道.假设作者检查了它并且对 NOTE 没问题.".但是,我同意你的看法.我更喜欢让 CRAN 检查在所有平台上返回一个干净的OK".这样用户就可以毫无疑问地通过检查.

There was a thread on r-devel a while ago where somebody from r-core basically said (from memory) "NOTES are ok, you know. The assumption is that the author checked it and is ok with the NOTE.". But, I agree with you. I do prefer to have CRAN checks return a clean "OK" on all platforms. That way the user is left in no doubt that it passes checks ok.

这里是 r-devel 线程 我记得(从 2010 年 4 月开始).所以这似乎表明在某些情况下没有已知的方法可以避免注意,但这没关系.

Here is the r-devel thread I was remembering (from April 2010). So that appears to suggest that there are some situations where there is no known way to avoid the NOTE, but that's ok.

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

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