Skip to content

Commit

Permalink
check.ErgmTerm() now only allows a NULL argument if 1) it's listed in…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
krivit committed Jul 13, 2021
1 parent 2561533 commit 0768888
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: ergm
Version: 4.0-6570
Version: 4.0-6572
Date: 2021-07-13
Title: Fit, Simulate and Diagnose Exponential-Family Models for Networks
Authors@R: c(
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export(ERGM_STATE_C_CHANGED)
export(ERGM_STATE_RECONCILED)
export(ERGM_STATE_R_CHANGED)
export(ERGM_VATTR_SPEC)
export(ERGM_VATTR_SPEC_NULL)
export(LARGEST)
export(SMALLEST)
export(approx.hotelling.diff.test)
Expand Down
11 changes: 8 additions & 3 deletions R/check.ErgmTerm.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ ergm_Init_warn_once <- once(ergm_Init_warn)
#' @param varnames the vector of names of the possible arguments for
#' term X; default=NULL
#' @param vartypes the vector of types of the possible arguments for
#' term X, separated by commas; an empty string (`""`) or `NA` disables the check for that argument; default=NULL
#' term X, separated by commas; an empty string (`""`) or `NA` disables the check for that argument, and also see Details; default=NULL
#' @param defaultvalues the list of default values for the possible
#' arguments of term X; default=list()
#' @param required the logical vector of whether each possible
Expand All @@ -58,6 +58,10 @@ ergm_Init_warn_once <- once(ergm_Init_warn)
#' containing a named logical vector indicating whether a particular
#' argument had been set to its default.
#'
#' @details As a convenience, if an argument is optional *and* its
#' default is `NULL`, then `NULL` is assumed to be an acceptable
#' argument type as well.
#'
#' @import network
#' @export check.ErgmTerm
check.ErgmTerm <- function(nw, arglist, directed=NULL, bipartite=NULL, nonnegative=FALSE,
Expand Down Expand Up @@ -127,8 +131,9 @@ check.ErgmTerm <- function(nw, arglist, directed=NULL, bipartite=NULL, nonnegati
val <- out[[m]]

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

# Check deprecation (but only if passed explicitly)
Expand Down
4 changes: 4 additions & 0 deletions R/get.node.attr.R
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,10 @@ ergm_attr_levels.formula <- function(object, attr, nw, levels=sort(unique(attr))
#' @export
ERGM_VATTR_SPEC <- "function,formula,character,AsIs"

#' @rdname nodal_attributes-API
#' @export
ERGM_VATTR_SPEC_NULL <- "function,formula,character,AsIs,NULL"

#' @rdname nodal_attributes-API
#' @export
ERGM_LEVELS_SPEC <- "function,formula,character,numeric,logical,AsIs,NULL,matrix"
Expand Down
6 changes: 5 additions & 1 deletion man/check.ErgmTerm.Rd

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

1 change: 0 additions & 1 deletion man/ergm_model.Rd

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

5 changes: 5 additions & 0 deletions man/nodal_attributes-API.Rd

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

0 comments on commit 0768888

Please sign in to comment.