@@ -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
0 commit comments