Reproducible example:
Inspired from Hadley book on pacakges:
Create a new empty package called test
with NAMESPACE
file:
## file NAMESPACE
exportPattern("^[[:alpha:]]+")
And an R file R/package_var.R
:
## file R/package_var.R
var <- 0
change_var <- function() {
var <<- 1
}
Then build the package.
Now if you test the package in a new R session:
> library(test)
> var
0
> change_var()
Error in change_var() :
cannot change value of locked binding for 'var'
But right after this example Hadley states:
you can’t change the binding for objects in the package namespace (well, at least not without trying harder than this).
What is the hard way Hadley is talking about?