hmer
hmer copied to clipboard
Change R6 function without unlockBindings (development branch)
It would be useful to have a means by which the 'default' behaviour of emulators were to be changed - e.g. training emulators using emulator_from_data
and then modifying the implausibility function after the fact. One way would be the following code, commented out in Emulator
:
set = function(name, replacement) {
if (is.null(self[[name]])) stop("No attribute to replace.")
s_env <- environment(self[[name]])$self
p_env <- environment(self[[name]])
unlockBinding(name, s_env)
self[[name]] <- replacement
environment(self[[name]]) <- p_env
lockBinding(name, s_env)
invisible(self)
}
However, locking and unlocking bindings can be dangerous. A nicer (and safer) means of doing this would be very useful!