Skip to content

no visible binding for global variable for CRAN check #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
kongdd opened this issue Jul 18, 2021 · 4 comments
Open

no visible binding for global variable for CRAN check #57

kongdd opened this issue Jul 18, 2021 · 4 comments
Assignees

Comments

@kongdd
Copy link

kongdd commented Jul 18, 2021

when using zeallot, package can't pass CRAN check:

c(d_fit, info_peak) %<-% rough_fitting(INPUT)
# checking R code for possible problems ... NOTE
opt_season: no visible binding for global variable 'd_fit'
opt_season: no visible binding for global variable 'info_peak'

Undefined global functions or variables:
d_fit info_peak

Any suggestions?

joeroe added a commit to joeroe/cleanc14 that referenced this issue Mar 7, 2022
Causes an R CMD check note: r-lib/zeallot#57

Also specify where c14_lab_code thesaurus comes from, for the same reason.
@markfairbanks
Copy link

To pass CRAN checks you just need to use globalVariables() somewhere in your package to let CRAN checks know to ignore these variables.

your_function <- function(val) {
  c(d_fit, info_peak) %<-% rough_fitting(INPUT)
}

globalVariables(c("d_fit", "info_peak"))

You can specify all such variables throughout your package in a single globalVariables() call, or you can use it multiple times throughout the package.

@wleoncio
Copy link

Using globalVariables() is quite a controversial thing. The documentation for the function itself gives an example involving some local variables that codetools fails to find, but ends up stating that "it is much better practice to write code that can be checked thoroughly". In any case, I feel it's improper to declare variables as global when they are not.

Another solution would be to simply initialize the variables before the assignment:

d_fit <- info_peak <- NA  # or whatever makes more sense than NA
c(d_fit, info_peak) %<-% rough_fitting(INPUT)

wleoncio added a commit to ocbe-uio/rBAPS that referenced this issue Dec 22, 2022
@nteetor nteetor closed this as completed Apr 15, 2025
@nteetor
Copy link
Member

nteetor commented Apr 16, 2025

The dotty package includes a fix for this, https://github.com/kevinushey/dotty/blob/main/R/dotify.R

@nteetor
Copy link
Member

nteetor commented Apr 17, 2025

The development version now includes a zeallous() function. Call this function in a package's .onLoad function to prevent the visible binding NOTEs produced by R CMD check.

.onLoad <- function(libname, pkgname) {
  zeallous()
}

Created on 2025-04-17 with reprex v2.1.1

Thank you to @kevinushey and the dotty package for making me aware of codetools and this approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants