Example of R CMD check No visible binding for global variable
NOTE
when defining a variable in a S3 generic and calling it in a method.
Install with:
# install.packages("devtools")
devtools::install_github("vgherard/globalReprex")
The function greet()
is an S3 generic defined by:
# greet <- function(object) {
# greeting <- "hola"
# UseMethod("greet", object)
# }
#
# greet.character <- function(object)
# paste(greeting, object)
This works as expected:
library(globalReprex)
greet("you")
## [1] "hola you"
However R CMD check gives the following NOTE:
- greet.character: no visible binding for global variable ‘greeting’ Undefined global functions or variables: greeting