rwarningsplyrr-packagepackage-development

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

In that scenario everything works smoothly by using aes_string instead of aes. However, this is not possible with plyr afaik.

The problem arises when I reference column names in my data frame via ddply for example.

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.

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?

Best, Michael


Solution

  • There are several workarounds. The easiest is to just assign NULL to all variables with no visible binding.

    VarA <- VarB <- VarC <- VarD <- VarE <- NULL
    

    A more elegant solution is to use as.quoted and substitute. UPDATE by @Dr. Mike: the call to as.quoted need to be encapsulated with c().

    ddply(mydf, 
          as.quoted(c('VarA', 'VarB', 'VarC', 'VarD')), 
          summarize, 
          sum = sum(substitute(VarE)))