1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
#' @title Wrapper for stop and sprintf
#'
#' @description
#' A wrapper for \code{\link{stop}} with \code{\link{sprintf}} applied to the arguments.
#' Notable difference is that error messages are not truncated to 1000 characters
#' by default.
#'
#' @param ... [any]\cr
#' See \code{\link{sprintf}}.
#' @param warning.length [\code{integer(1)}]\cr
#' Number of chars after which the error message
#' gets truncated, see ?options.
#' Default is 8170.
#' @return Nothing.
#' @export
#' @examples
#' err = "an error."
#' try(stopf("This is %s", err))
stopf = function(..., warning.length = 8170L) {
msg = sprintf(...)
obj = simpleError(msg, call = sys.call(sys.parent()))
old.opt = getOption("warning.length")
on.exit(options(warning.length = old.opt))
options(warning.length = warning.length)
stop(obj)
}
|