Skip to content

Commit

Permalink
ergm_Init_*() messaging functions now have their base-R based counter…
Browse files Browse the repository at this point in the history
…parts with similar argument interpretation but different defaults, suppressing the caller. Also, ergm_Init_abort() now takes a call= argument and propagates it.
  • Loading branch information
krivit committed Jun 5, 2024
1 parent 5fe1564 commit 90020d2
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 5 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: ergm
Version: 4.7-7364
Date: 2024-06-03
Version: 4.7-7367
Date: 2024-06-05
Title: Fit, Simulate and Diagnose Exponential-Family Models for Networks
Authors@R: c(
person(c("Mark", "S."), "Handcock", role=c("aut"), email="[email protected]"),
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,11 @@ export(ergm_Cstate_clear)
export(ergm_GWDECAY)
export(ergm_Init_abort)
export(ergm_Init_inform)
export(ergm_Init_message)
export(ergm_Init_stop)
export(ergm_Init_try)
export(ergm_Init_warn)
export(ergm_Init_warning)
export(ergm_MCMC_sample)
export(ergm_MCMC_slave)
export(ergm_SAN_slave)
Expand Down
34 changes: 32 additions & 2 deletions R/ergm.errors.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,31 @@
#' character vector, concatenated into the message.
#' @param default.loc Optional name for the source of the error, to be
#' used if an initializer cannot be autodetected.
#' @param call.,call See [stop()] and [abort()] respectively; note the
#' different defaults.
#'
#' @note At this time, the \CRANpkg{rlang} analogues
#' `ergm_Init_abort()`, `ergm_Init_warn()`, and `ergm_Init_inform()`
#' all concatenate their arguments like their base \R
#' counterparts. This may change in the future, and if you wish to
#' retain their old behavior, please switch to their base \R
#' analogues `ergm_Init_stop()`, `ergm_Init_warning()`, and
#' `ergm_Init_message()`.
#' @importFrom rlang abort
#' @seealso [stop()], [abort()]
#' @name ergm-errors
#' @keywords internal
#' @export
ergm_Init_abort <- function(..., default.loc=NULL){
ergm_Init_abort <- function(..., default.loc=NULL, call=NULL){
loc <- traceback.Initializers() %>% format_traceback()
abort(paste0('In ', NVL(loc, default.loc, "unknown function"), ': ', ...))
abort(paste0('In ', NVL(loc, default.loc, "unknown function"), ': ', ...), call=call)
}

#' @rdname ergm-errors
#' @export
ergm_Init_stop <- function(..., call. = FALSE, default.loc=NULL){
loc <- traceback.Initializers() %>% format_traceback()
stop(paste0('In ', NVL(loc, default.loc, "unknown function"), ': '), ..., call.=call.)
}

#' @rdname ergm-errors
Expand All @@ -38,6 +54,13 @@ ergm_Init_warn <- function(..., default.loc=NULL){
warn(paste0('In ', NVL(loc, default.loc, "unknown function"), ': ', ...))
}

#' @rdname ergm-errors
#' @export
ergm_Init_warning <- function(..., call. = FALSE, default.loc=NULL){
loc <- traceback.Initializers() %>% format_traceback()
warning(paste0('In ', NVL(loc, default.loc, "unknown function"), ': '), ..., call.=call.)
}

#' @rdname ergm-errors
#' @seealso [message()], [inform()]
#' @importFrom rlang inform
Expand All @@ -47,6 +70,13 @@ ergm_Init_inform <- function(..., default.loc=NULL){
inform(paste0('In ', NVL(loc, default.loc, "unknown function"), ': ', ...))
}

#' @rdname ergm-errors
#' @export
ergm_Init_message <- function(..., default.loc=NULL){
loc <- traceback.Initializers() %>% format_traceback()
message(paste0('In ', NVL(loc, default.loc, "unknown function"), ': '), ...)
}

#' @describeIn ergm-errors A helper function that evaluates the
#' specified expression in the caller's environment, passing any
#' errors to [ergm_Init_abort()].
Expand Down
23 changes: 22 additions & 1 deletion man/ergm-errors.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 90020d2

Please sign in to comment.