You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
example<-function() {
mtcars|>dplyr::filter(rlang::.data$cyl==4)
}
globals::globalsOf(example, mustExist=T)
# No error thrown...
However, when a global variable is defined using the utils::globalVariables function, the globals::globalsOf function throws an error.
example<-function() {
utils::globalVariables(c("cyl"))
mtcars|>dplyr::filter(cyl==4)
}
globals::globalsOf(example, mustExist=T)
#> Error in globalsByName(names, envir = envir, mustExist = mustExist): Identified global objects via static code inspection (function (); {; utils::globalVariables(c("cyl")); dplyr::filter(mtcars, cyl == 4); }). Failed to locate global object in the relevant environments: 'cyl'
This is especially painful when developing R Shiny applications as a package.
I think adding this functionality would be a great addition, because is recommended in the book R Packages (2e) and in my humble opinion, it makes sense as the variable is defined globally.
What do you guys think? :)
The text was updated successfully, but these errors were encountered:
The “no visible binding” note is a peculiarity of using dplyr and unquoted variable names inside a package, where the use of bare variable names (english and temp) looks suspicious. You can add either of these lines to any file below R/ to eliminate this note
Using utils::globalVariables() is there to "eliminate this note". It does not actually set a global value that can be found.
Previous issue on finding globals given non-standard evaluation: #35
I don't believe utils::globalVariables() should be supported by {globals} even though the name implies "setting a globally available name".
If a function uses data masking, the function
globals::globalsOf(...)
throws an error, as expected.This can be fixed with two things: defining the variable as NULL
or using pronouns.
However, when a global variable is defined using the
utils::globalVariables
function, theglobals::globalsOf
function throws an error.This is especially painful when developing R Shiny applications as a package.
I think adding this functionality would be a great addition, because is recommended in the book R Packages (2e) and in my humble opinion, it makes sense as the variable is defined globally.
What do you guys think? :)
The text was updated successfully, but these errors were encountered: