hmer icon indicating copy to clipboard operation
hmer copied to clipboard

Change R6 function without unlockBindings (development branch)

Open andy-iskauskas opened this issue 2 years ago • 0 comments

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!

andy-iskauskas avatar Jan 31 '23 15:01 andy-iskauskas