[R-pkg-devel] CRAN pre-test failed on NOTE "no visible binding for global variable"

Berlanga, Antonio J @@ber|@ng@ @end|ng |rom |mper|@|@@c@uk
Tue Jul 2 14:13:17 CEST 2019


Hi r-package-devel,

I've submitted my first package but it failed the CRAN pre-tests on
NOTES. I got:

- my email

- an extra non-standard file (which I have now added to .Rbuildignore)

- NOTEs on "no visible global function definition"

The first two I assume are harmless. The third I do not know how to fix
(possible solutions below). Can it be ignored and suggest the fail was a
false-positive?

The third NOTE is:

#######

Flavor: r-devel-linux-x86_64-debian-gcc, r-devel-windows-ix86+x86_64
Check: R code for possible problems, Result: NOTE
  epi_clean_count_classes: no visible global function definition for
    '%>%'
  epi_clean_count_classes: no visible binding for global variable '.'
  epi_plot_heatmap: no visible binding for global variable 'Var1'
  epi_plot_heatmap: no visible binding for global variable 'Var2'
  epi_plot_heatmap: no visible binding for global variable 'value'
  epi_plot_heatmap_triangle: no visible binding for global variable
    'Var1'
  epi_plot_heatmap_triangle: no visible binding for global variable
    'Var2'
  epi_plot_heatmap_triangle: no visible binding for global variable
    'value'
  epi_plot_heatmap_triangle: no visible global function definition for
    'element_text'
  epi_plot_heatmap_triangle: no visible global function definition for
    'coord_fixed'
  epi_plot_heatmap_triangle: no visible global function definition for
    'element_blank'
  epi_plot_heatmap_triangle: no visible global function definition for
    'element_rect'
  epi_plot_heatmap_triangle: no visible global function definition for
    'guide_colorbar'
  epi_stats_summary: no visible global function definition for '%>%'
  epi_stats_tidy: no visible global function definition for '%>%'
  epi_stats_tidy: no visible binding for global variable '.'
  epi_stats_tidy: no visible binding for global variable 'x'
  epi_stats_tidy: no visible binding for global variable 'n'
  epi_stats_tidy: no visible binding for global variable 'id'
  Undefined global functions or variables:
    %>% . Var1 Var2 coord_fixed element_blank element_rect element_text
    guide_colorbar id n value x
#######


Solutions seem to cause errors elsewhere and there does not appear to be
an ideal one unfortunately. It seems to me that adding a file in the
directory 'R' containing eg:

#######

if(getRversion() >= "2.15.1") utils::globalVariables(c("."))

#######

is one of the preferred ways. This seems far from ideal though.

Another option is to import the package and function in the namespace
with eg @importFrom rlang .data

This also seems to cause errors in my case however as I then get
problems with R CMD check with conflicts when including or excluding
such packages from the DESCRIPTION file (I'm sure I'm missing something
though but can't see how to fix it).

See discussions in:

https://github.com/r-lib/devtools/issues/1714
feature request: R CMD check and no visible binding for global variable
· Issue #1714 · r-lib/devtools

https://stackoverflow.com/questions/40251801/how-to-use-utilsglobalvariables
r - how to use utils::globalVariables - Stack Overflow

https://github.com/tidyverse/magrittr/issues/29
R CMD check and no visible binding for global variable '.' · Issue #29 ·
tidyverse/magrittr

https://github.com/STAT545-UBC/Discussion/issues/451
Writing R Packages: no visible binding for global variable · Issue #451
· STAT545-UBC/Discussion


My current thought is to keep the NOTEs as they are to remind me what
I've done and ignore them in the CRAN checks.

Help would be appreciated though (!).

Best wishes,
Antonio





More information about the R-package-devel mailing list