From 84bf2f459c186a07c04d2df1d3c490523509e740 Mon Sep 17 00:00:00 2001 From: olivroy <52606734+olivroy@users.noreply.github.com> Date: Fri, 26 Apr 2024 08:51:01 -0400 Subject: [PATCH 1/2] Show how to use call = `base::call()` --- R/cnd-abort.R | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/R/cnd-abort.R b/R/cnd-abort.R index da74cb7e6..70ceaece1 100644 --- a/R/cnd-abort.R +++ b/R/cnd-abort.R @@ -245,7 +245,15 @@ #' abort(msg, parent = err) #' }) #' ) -#' +#' # Hard-code call +#' f <- function() { +#' abort(call = call("the_source_fn")) +#' } +#' g <- function() { +#' f() +#' } +#' # will show that error occured in `the_source_fn()` +#' try(g()) #' } #' @export abort <- function(message = NULL, From fc4b244892c423b1f1970c340eb075af4809486d Mon Sep 17 00:00:00 2001 From: Lionel Henry Date: Fri, 31 May 2024 12:52:19 +0200 Subject: [PATCH 2/2] Tweak wording and fix missing `message` argument --- R/cnd-abort.R | 9 ++++++--- man/abort.Rd | 11 +++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/R/cnd-abort.R b/R/cnd-abort.R index 70ceaece1..f9bb80978 100644 --- a/R/cnd-abort.R +++ b/R/cnd-abort.R @@ -245,15 +245,18 @@ #' abort(msg, parent = err) #' }) #' ) -#' # Hard-code call +#' +#' # You can also hard-code the call when it's not easy to +#' # forward it from the caller #' f <- function() { -#' abort(call = call("the_source_fn")) +#' abort("my message", call = call("my_function")) #' } #' g <- function() { #' f() #' } -#' # will show that error occured in `the_source_fn()` +#' # 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{