Skip to content

Commit 0768888

Browse files
committed
check.ErgmTerm() now only allows a NULL argument if 1) it's listed in the vartypes explicitly or 2) it's optional and the default is NULL; new constant, ERGM_VATTR_SPEC_NULL has been defined, equivalent to ERGM_VATTR_SPEC plus NULL.
fixes #349
1 parent 2561533 commit 0768888

File tree

7 files changed

+24
-6
lines changed

7 files changed

+24
-6
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: ergm
2-
Version: 4.0-6570
2+
Version: 4.0-6572
33
Date: 2021-07-13
44
Title: Fit, Simulate and Diagnose Exponential-Family Models for Networks
55
Authors@R: c(

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ export(ERGM_STATE_C_CHANGED)
160160
export(ERGM_STATE_RECONCILED)
161161
export(ERGM_STATE_R_CHANGED)
162162
export(ERGM_VATTR_SPEC)
163+
export(ERGM_VATTR_SPEC_NULL)
163164
export(LARGEST)
164165
export(SMALLEST)
165166
export(approx.hotelling.diff.test)

R/check.ErgmTerm.R

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ ergm_Init_warn_once <- once(ergm_Init_warn)
4141
#' @param varnames the vector of names of the possible arguments for
4242
#' term X; default=NULL
4343
#' @param vartypes the vector of types of the possible arguments for
44-
#' term X, separated by commas; an empty string (`""`) or `NA` disables the check for that argument; default=NULL
44+
#' term X, separated by commas; an empty string (`""`) or `NA` disables the check for that argument, and also see Details; default=NULL
4545
#' @param defaultvalues the list of default values for the possible
4646
#' arguments of term X; default=list()
4747
#' @param required the logical vector of whether each possible
@@ -58,6 +58,10 @@ ergm_Init_warn_once <- once(ergm_Init_warn)
5858
#' containing a named logical vector indicating whether a particular
5959
#' argument had been set to its default.
6060
#'
61+
#' @details As a convenience, if an argument is optional *and* its
62+
#' default is `NULL`, then `NULL` is assumed to be an acceptable
63+
#' argument type as well.
64+
#'
6165
#' @import network
6266
#' @export check.ErgmTerm
6367
check.ErgmTerm <- function(nw, arglist, directed=NULL, bipartite=NULL, nonnegative=FALSE,
@@ -127,8 +131,9 @@ check.ErgmTerm <- function(nw, arglist, directed=NULL, bipartite=NULL, nonnegati
127131
val <- out[[m]]
128132

129133
# Check type
130-
if(!is.na(vartypes[m]) && nchar(vartypes[m])
131-
&& all(sapply(strsplit(vartypes[m],",",fixed=TRUE)[[1]], function(vartype) !is.null(val) && !is(val, vartype))))
134+
if(!is.na(vartypes[m]) && nchar(vartypes[m]) &&
135+
!(is.null(val) && !required[[m]] && is.null(defaultvalues[[m]])) &&
136+
all(sapply(strsplit(vartypes[m],",",fixed=TRUE)[[1]], function(vartype) !is(val, vartype))))
132137
ergm_Init_abort(sQuote(name), " argument is not of any of the expected (", vartypes[m], ") types.")
133138

134139
# Check deprecation (but only if passed explicitly)

R/get.node.attr.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,10 @@ ergm_attr_levels.formula <- function(object, attr, nw, levels=sort(unique(attr))
644644
#' @export
645645
ERGM_VATTR_SPEC <- "function,formula,character,AsIs"
646646

647+
#' @rdname nodal_attributes-API
648+
#' @export
649+
ERGM_VATTR_SPEC_NULL <- "function,formula,character,AsIs,NULL"
650+
647651
#' @rdname nodal_attributes-API
648652
#' @export
649653
ERGM_LEVELS_SPEC <- "function,formula,character,numeric,logical,AsIs,NULL,matrix"

man/check.ErgmTerm.Rd

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/ergm_model.Rd

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/nodal_attributes-API.Rd

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)