File: stopifnot.R

package info (click to toggle)
r-cran-openssl 1.4.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,288 kB
  • sloc: ansic: 3,021; sh: 97; makefile: 5
file content (10 lines) | stat: -rw-r--r-- 365 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
# custom stopifnot() that includes a stack trace
stopifnot <- function(...){
  expr <- as.list(match.call(expand.dots = TRUE)[-1])
  values <- vapply(list(...), isTRUE, logical(1))
  if(!all(values)){
    cl <- utils::tail(sys.calls(), 2)[[1]]
    err <- sprintf("check failed: (%s)", deparse(expr[[which(!values)[1]]]))
    stop(simpleError(err, call = cl))
  }
}