[英]How do I get rid of the NOTE's generated by R CMD check when using for example ddply in my package?
I have a problem similar to, yet distinct from, How can I handle R CMD check "no visible binding for global variable" notes when my ggplot2 syntax is sensible? 我有一个类似但又不同的问题, 当我的ggplot2语法合理时 , 如何处理R CMD检查“对全局变量无可见绑定”注释? .
。
In that scenario everything works smoothly by using aes_string instead of aes. 在那种情况下,通过使用aes_string而不是aes,一切都会顺利进行。 However, this is not possible with plyr afaik.
但是,plyr afaik无法做到这一点。
The problem arises when I reference column names in my data frame via ddply for example. 例如,当我通过ddply引用数据框中的列名时,就会出现问题。
ddply(mydf, .(VarA, VarB, VarC, VarD), summarize, sum = sum(VarE))
#
# MyPackage: no visible binding for
# global variable ‘VarA’
This code is completely valid and sane and even though I understand the use of the NOTE's they still clutter up the other messages in the output windows making package development a pain and actually enforcing the developers to ignore NOTEs. 这段代码是完全有效和理智的,即使我了解NOTE的用法,它们仍然会使输出窗口中的其他消息杂乱无章,这使程序包开发非常痛苦,并实际上迫使开发人员忽略NOTES。
What is the correct way to get rid of these notes? 摆脱这些笔记的正确方法是什么? Or alternatively what is the correct way to write the code in a way that R CMD check accepts without giving NOTE's?
或者,以正确的方式编写代码(R CMD检查接受而不给出NOTE的方式)是什么?
Best, Michael 最好,迈克尔
There are several workarounds. 有几种解决方法。 The easiest is to just assign
NULL
to all variables with no visible binding. 最简单的方法是将
NULL
分配给所有没有可见绑定的变量。
VarA <- VarB <- VarC <- VarD <- VarE <- NULL
A more elegant solution is to use as.quoted
and substitute
. 更优雅的解决方案是使用
as.quoted
和substitute
。 UPDATE by @Dr. @Dr更新 Mike: the call to
as.quoted
need to be encapsulated with c()
. Mike:对
as.quoted
的调用需要使用c()
封装。
ddply(mydf,
as.quoted(c('VarA', 'VarB', 'VarC', 'VarD')),
summarize,
sum = sum(substitute(VarE)))
You can avoid CMD check warnings by declaring global variables: 您可以通过声明全局变量来避免CMD检查警告:
globalVariables(c("VarA", "VarB"))
Please read ?globalVariables
before using, and make sure the appropriate R version is added to your DESCRIPTION. 使用前请阅读
?globalVariables
,并确保将适当的R版本添加到您的DESCRIPTION。
Avoiding the use of globals by quoting is always preferable. 最好避免通过引用使用全局变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.