Created
July 1, 2022 11:53
-
-
Save pteetor/24201b1fa9a33f174121023541fe7506 to your computer and use it in GitHub Desktop.
R functions for reporting fatal errors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' @export | |
fatal = function(..., sep = " ", caller = NULL) { | |
caller <- caller %||% as.list(sys.call(-1))[[1]] | |
msg <- paste0("[", caller, "] ", paste(..., sep = sep)) | |
stop(msg, call. = FALSE) | |
} | |
#' @export | |
fatalIf = function(cond, ..., caller = NULL) { | |
if (cond) { | |
fatal(..., | |
caller = caller %||% as.list(sys.call(-1))[[1]] ) | |
} | |
} | |
#' @export | |
fatalIfNot = function(cond, ..., caller = NULL) { | |
if (!cond) { | |
fatal(..., | |
caller = caller %||% as.list(sys.call(-1))[[1]] ) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment