简体   繁体   English

在包装中使用ddply时,如何摆脱R CMD检查生成的NOTE?

[英]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.quotedsubstitute 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.

相关问题 如何解决R CMD check --as-cran中的错误,以使我的R程序包在CRAN上被接受? - How do I fix errors from R CMD check --as-cran to get my R package accepted on CRAN? R CMD检查错误:如何摆脱Windows上devel R包中的隐藏文件和目录? - R CMD check error : how to get rid of hidden files and directory in devel R package on windows? R CMD 检查注意:“全局变量没有可见绑定”,在 S3 泛型中定义变量并在方法中使用它时 - R CMD check NOTE: `No visible binding for global variable`, when defining a variable in an S3 generic and using it in a method 在R中使用plot()时如何摆脱网格? - How do I get rid of grids when using plot() in R? R CMD Check: Unusual Checking install package size note - R CMD Check: Unusual Checking installed package size note 将 csv 导入 r 时 a-hat 是什么意思(以及如何摆脱它)? - What's an a-hat mean when importing a csv into r (and how do I get rid of it)? 如何在R上使用ddply函数? - How do I use the ddply function on R? 我如何解决“包 &#39;ddply&#39; 不可用(对于 R 版本 3.6.2)” - How do I go about resolving "package ‘ddply’ is not available (for R version 3.6.2)" 在 R 中使用 sf 包中的 st_read 时,如何从 Postgre 表中获得正确的编码 - How do I get correct encoding from my Postgre table when using st_read from the sf package in R 关于 R CMD 检查中 graphics::curve() 的注释 - A note on graphics::curve() in R CMD check
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM