R/on-load.R

Defines functions maybe_restart convert_message_to_package_startup_message .onLoad

#' @importFrom debugme debugme

.onLoad <- function(libname, pkgname) {
  debugme()

  # This will issue a message if phantomjs isn't found, converting the regular
  # message to a packageStartupMessage.
  convert_message_to_package_startup_message({
    find_phantom()
  })
}


# Evaluate an expression, and if it emits any messsages, convert them to
# packageStartupMessage.
convert_message_to_package_startup_message <- function(expr) {
  withCallingHandlers(
    force(expr),
    message = function(cnd) {
      packageStartupMessage(conditionMessage(cnd))
      maybe_restart("muffleMessage")
    }
  )
}


# This is equivalent to tryInvokeRestart, but that function is available only in
# R 4.0 and above.
maybe_restart <- function(restart) {
  if (!is.null(findRestart(restart))) {
    invokeRestart(restart)
  }
}

Try the shinytest package in your browser

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

shinytest documentation built on March 31, 2023, 11:09 p.m.