Closed richierocks closed 7 years ago
Unfortunately, this is what R does with active bindings:
e <- new.env()
makeActiveBinding("x", function() { 1 }, e)
e$x <- 2
# Error in (function () : unused argument (quote(2))
I wish there were a straightforward way to make nicer error messages, but I don't think it's possible without changing code in R itself.
What about:
e <- new.env()
makeActiveBinding("x", function(value) {
if (!missing(value)) {
stop("x is read only", call. = FALSE)
}
1
}, e)
e$x
e$x <- 2
If I create a class with a read-only active binding, then try to set the value, the error message is a bit obscure. To reproduce:
It would be clearer for the user if the message explained that
a_field
was read-only.