mlr-org / mlr3misc

Miscellaneous helper functions for mlr3
https://mlr3misc.mlr-org.com
GNU Lesser General Public License v3.0
11 stars 2 forks source link

register callback to namespace being loaded #39

Closed mb706 closed 3 years ago

mb706 commented 4 years ago

UI something like

register_mlr3 = function() { ... }
register_mlr3pipelines = function() { ... }
.onLoad = function(libname, pkgname) {
  mlr3misc::react_to_namespace("mlr3", register_mlr3)
  mlr3misc::react_to_namespace("mlr3pipelines", register_mlr3pipelines)
}

should look something like

react_to_namespace = function(namespace, callback) {
  if (already_loaded(namespace)) callback()
  setHook(packageEvent(namespace, "onLoad"), .......)
  setHook(packageEvent(namespace_name_of(parent.frame()), "onUnload"), function(...) { < do the onUnload stuff > })
}