tests/testthat/testUserLoadHookError/R/testUserLoadHookError.R

the <- new.env()

# Can't fully reset onLoad hook so only run once in case of repeated
# `test()` calls
the$ran_already <- FALSE

.onLoad <- function(...) {
  setHook(
    packageEvent("testUserLoadHookUpstream", "onLoad"),
    function(...) {
      if (the$ran_already) {
        return()
      }
      the$ran_already <- TRUE

      rlang::signal("", "hook_was_run_error")
      stop("The message.")
    }
  )
}

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.