Skip to content

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

4 messages · Berlanga, Antonio J, Iñaki Ucar, Georgi Boshnakov +1 more

#
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
#
ra?l

On Tue, 2 Jul 2019 at 14:18, Berlanga, Antonio J
<a.berlanga at imperial.ac.uk> wrote:
If you use NSE in your package, this is the best solution. You may
also switch to SE.

I?aki
#
Using such a general pattern eventually and  inevitably will prevent the check from reporting legitimate bugs. 
One alternative is to list explicitly the variables in question and make sure that they are not commonly used names like 'x'. 
If that is not practical and you use non-standard evaluation a lot,  consider '.data' from package 'lang' , see its documentation and/or Google it 
to find out how to use it. 

#' @importFrom rlang .data


Georgi Boshnakov

-----Original Message-----
From: R-package-devel [mailto:r-package-devel-bounces at r-project.org] On Behalf Of I?aki Ucar
Sent: 02 July 2019 15:19
To: Berlanga, Antonio J
Cc: r-package-devel at r-project.org
Subject: Re: [R-pkg-devel] CRAN pre-test failed on NOTE "no visible binding for global variable"

ra?l

On Tue, 2 Jul 2019 at 14:18, Berlanga, Antonio J
<a.berlanga at imperial.ac.uk> wrote:
If you use NSE in your package, this is the best solution. You may
also switch to SE.

I?aki

______________________________________________
R-package-devel at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel
#
On 02/07/2019 11:00 a.m., Georgi Boshnakov wrote:
I believe globalVariables() takes a vector of names, not a regular 
expression for names.  So that's not so general, it's just the name ".".

Duncan Murdoch