From d7be54d8155a70ddb717ad3dac471f8a3b2b7bb2 Mon Sep 17 00:00:00 2001 From: olivroy <52606734+olivroy@users.noreply.github.com> Date: Fri, 31 May 2024 06:58:23 -0400 Subject: [PATCH] Show how to use call = `base::call()` in `abort()` (#1704) * Show how to use call = `base::call()` * Tweak wording and fix missing `message` argument --------- Co-authored-by: Lionel Henry --- R/cnd-abort.R | 11 +++++++++++ man/abort.Rd | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/R/cnd-abort.R b/R/cnd-abort.R index da74cb7e6..f9bb80978 100644 --- a/R/cnd-abort.R +++ b/R/cnd-abort.R @@ -246,6 +246,17 @@ #' }) #' ) #' +#' # You can also hard-code the call when it's not easy to +#' # forward it from the caller +#' f <- function() { +#' abort("my message", call = call("my_function")) +#' } +#' g <- function() { +#' f() +#' } +#' # Shows that the error occured in `my_function()` +#' try(g()) +#' #' } #' @export abort <- function(message = NULL, diff --git a/man/abort.Rd b/man/abort.Rd index edcd31366..1fdcbd816 100644 --- a/man/abort.Rd +++ b/man/abort.Rd @@ -338,6 +338,17 @@ try( }) ) +# You can also hard-code the call when it's not easy to +# forward it from the caller + f <- function() { + abort("my message", call = call("my_function")) +} +g <- function() { + f() +} +# Shows that the error occured in `my_function()` +try(g()) + } } \seealso{