tests/testthat/testUserLoadHook/R/testUserLoadHook.R

.onLoad <- function(...) {
  stopifnot(!environmentIsLocked(asNamespace("testUserLoadHook")))

  setHook(
    packageEvent("testUserLoadHookUpstream", "onLoad"),
    function(...) {
      stopifnot(environmentIsLocked(asNamespace("testUserLoadHookUpstream")))

      # The package exports are populated when user onLoad hooks are run
      stopifnot(is.null(testUserLoadHookUpstream::foo()))

      rlang::signal("", "hook_was_run")
    }
  )
}

Try the pkgload package in your browser

Any scripts or data that you put into this service are public.

pkgload documentation built on Sept. 22, 2023, 9:06 a.m.