Search code examples
rcran

R CMD check: no visible binding for global variable (when using a data/ dataset in the package)


Slightly different versions of this question have been asked before but I haven't seen a good answer yet.

I have a very simple repro using the very good source code of ggplot2:

Go into any file in ggplot2/R/ and add a line that references the "diamonds" dataset included in ggplot2/data/diamonds.r.

Then attempt to build/check the package, (ie: R CMD build .; R CMD check --as-cran ggplot2_3.0.0.9000.tar.gz)

In my arbitrary example I added diamonds to line 436 in theme.r and got this note when trying to check:

* checking R code for possible problems ... NOTE
plot_theme: no visible binding for global variable ‘diamonds’
Undefined global functions or variables:
  diamonds

I run into this problem in our package which we want to submit to CRAN. AFAIK we are following best practices by using data/ourdataset.r and then "ourdataset" in our R/ code. And yet, we get this NOTE failure.

What are we doing wrong? If this NOTE comes up for a package like ggplot2, I am at a loss as to whether we are doing something wrong or this is something that should be fixed in CHECK. CHECK has been fantastic so far but I am stumped on this one.

Thanks!


Solution

  • Usually, to get rid of that Note you just have to add a reference like this:

    ggplot2::diamonds