quote({ # Not run
# First add `run_on_load()` to your `.onLoad()` hook,
# then use `on_load()` anywhere in your package
.onLoad <- function(lib, pkg) {
run_on_load()
}
# Register a method on load
on_load({
s3_register("foo::bar", "my_class")
})
# Assign an object on load
var <- NULL
on_load({
var <- foo()
})
# To use `on_package_load()` at top level, wrap it in `on_load()`
on_load({
on_package_load("foo", message("foo is loaded"))
})
# In functions it can be called directly
f <- function() on_package_load("foo", message("foo is loaded"))
})
Run the code above in your browser using DataLab