-
Notifications
You must be signed in to change notification settings - Fork 184
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
conflicting note on global variable assignment #1969
Comments
is this part of a script or a package? |
Issue originally occurred in a package, but the above example is a script for the sake of reproducing. |
Your code doesn't do what you think it does, and the warning is justified. If you want to overwrite |
Sorry for being unclear. |
Thanks @AshesITR , it works well with scripts. In package, when I run lint active package from R studio, I don't get any notes. However, upon running
Note that, I have different code in case of R script in package.
In above, if I use
I have |
@krishnakeshav I recommend you read the R Packages section on internal state for packages to see how you should define and use global state in Packages. Here is a MWE copied from there: the <- new.env(parent = emptyenv())
the$favorite_letters <- letters[1:3]
#' Report my favorite letters
#' @export
mfl2 <- function() {
the$favorite_letters
}
#' Change my favorite letters
#' @export
set_mfl2 <- function(l = letters[24:26]) {
old <- the$favorite_letters
the$favorite_letters <- l
invisible(old)
} For plain scripts, the error "cannot change value of locked binding ..." will disappear. |
This worked for me. Thanks again @AshesITR |
lintr gives conflicting notes for scenario below -
It's likely for variable to be used outside the function when I have already declared it to be global with
utils::globalVariables(c("g_var"))
It should have been resolved as per this.
The text was updated successfully, but these errors were encountered: