From 90020d23ecdb32ecff0c8a18b5c83ea04fd02339 Mon Sep 17 00:00:00 2001
From: "Pavel N. Krivitsky"
Date: Wed, 5 Jun 2024 18:52:33 +1000
Subject: [PATCH] ergm_Init_*() messaging functions now have their base-R based
counterparts with similar argument interpretation but different defaults,
suppressing the caller. Also, ergm_Init_abort() now takes a call= argument
and propagates it.
---
DESCRIPTION | 4 ++--
NAMESPACE | 3 +++
R/ergm.errors.R | 34 ++++++++++++++++++++++++++++++++--
man/ergm-errors.Rd | 23 ++++++++++++++++++++++-
4 files changed, 59 insertions(+), 5 deletions(-)
diff --git a/DESCRIPTION b/DESCRIPTION
index 415d5d0f7..327b8edea 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -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="handcock@stat.ucla.edu"),
diff --git a/NAMESPACE b/NAMESPACE
index 39199b5bd..f5570b7ca 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -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)
diff --git a/R/ergm.errors.R b/R/ergm.errors.R
index 511ea4cbb..d6ac8ef39 100644
--- a/R/ergm.errors.R
+++ b/R/ergm.errors.R
@@ -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
@@ -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
@@ -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()].
diff --git a/man/ergm-errors.Rd b/man/ergm-errors.Rd
index 93633aa5d..5ecbe7fd9 100644
--- a/man/ergm-errors.Rd
+++ b/man/ergm-errors.Rd
@@ -3,17 +3,26 @@
\name{ergm-errors}
\alias{ergm-errors}
\alias{ergm_Init_abort}
+\alias{ergm_Init_stop}
\alias{ergm_Init_warn}
+\alias{ergm_Init_warning}
\alias{ergm_Init_inform}
+\alias{ergm_Init_message}
\alias{ergm_Init_try}
\title{Sensible error and warning messages by \code{ergm} initializers}
\usage{
-ergm_Init_abort(..., default.loc = NULL)
+ergm_Init_abort(..., default.loc = NULL, call = NULL)
+
+ergm_Init_stop(..., call. = FALSE, default.loc = NULL)
ergm_Init_warn(..., default.loc = NULL)
+ergm_Init_warning(..., call. = FALSE, default.loc = NULL)
+
ergm_Init_inform(..., default.loc = NULL)
+ergm_Init_message(..., default.loc = NULL)
+
ergm_Init_try(expr)
}
\arguments{
@@ -23,6 +32,9 @@ character vector, concatenated into the message.}
\item{default.loc}{Optional name for the source of the error, to be
used if an initializer cannot be autodetected.}
+\item{call., call}{See \code{\link[=stop]{stop()}} and \code{\link[=abort]{abort()}} respectively; note the
+different defaults.}
+
\item{expr}{Expression to be evaluated (in the caller's
environment).}
}
@@ -39,6 +51,15 @@ specified expression in the caller's environment, passing any
errors to \code{\link[=ergm_Init_abort]{ergm_Init_abort()}}.
}}
+\note{
+At this time, the \CRANpkg{rlang} analogues
+\code{ergm_Init_abort()}, \code{ergm_Init_warn()}, and \code{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 \code{ergm_Init_stop()}, \code{ergm_Init_warning()}, and
+\code{ergm_Init_message()}.
+}
\seealso{
\code{\link[=stop]{stop()}}, \code{\link[=abort]{abort()}}