Skip to content

Commit 5d2cf23

Browse files
committed
I() operator constraint can now also take character strings and vectors.
1 parent 96eb045 commit 5d2cf23

3 files changed

Lines changed: 24 additions & 6 deletions

File tree

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: ergm
2-
Version: 4.12.1-7996
3-
Date: 2026-02-24
2+
Version: 4.12.1-7997
3+
Date: 2026-02-25
44
Title: Fit, Simulate and Diagnose Exponential-Family Models for Networks
55
Authors@R: c(
66
person(c("Mark", "S."), "Handcock", role=c("aut"), email="handcock@stat.ucla.edu"),

R/InitErgmConstraint.operator.R

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,34 @@ InitErgmConstraint.Dyads<-function(nw, arglist, ..., verify_dind = TRUE){
7373
#' # I(formula)
7474
#' @param formula a constraints formula
7575
#'
76-
#' @note `formula` can also be a [term_list].
76+
#' @note `formula` can also be a [`term_list`] or [`character`]. In
77+
#' the latter case, if there are multiple strings, they will be
78+
#' concatenated with `+`, and if they do not start with "~", one
79+
#' will be prepended. Its environment will be inherited from the
80+
#' top-level formula.
7781
#'
7882
#' @seealso [base::I()] (a.k.a. `AsIs`)
7983
#'
8084
#' @template ergmConstraint-general
8185
#'
8286
#' @concept operator
83-
InitErgmConstraint.I <- function(nw, arglist, ...) {
87+
InitErgmConstraint.I <- function(nw, arglist, ..., env) {
8488
a <- check.ErgmTerm(nw, arglist,
8589
varnames = c("formula"),
86-
vartypes = c("formula"),
90+
vartypes = c("formula,character,term_list"),
8791
defaultvalues = list(NULL),
8892
required = c(TRUE))
8993

94+
f <- a$formula
95+
96+
if (is.character(f)) {
97+
if (length(f) > 1) f <- paste(f, collapse = " + ")
98+
99+
if (!startsWith(trimws(f, "left"), "~")) f <- paste0("~", f)
100+
101+
f <- as.formula(f, env)
102+
}
103+
90104
ergm_conlist(a$formula, nw, ...)
91105
}
92106

man/I-ergmConstraint-ca2567ac.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.

0 commit comments

Comments
 (0)