Skip to content

Commit ea9b61b

Browse files
committed
Fixed up and streamlined ergmProposal table printing.
1 parent c4d87be commit ea9b61b

4 files changed

Lines changed: 42 additions & 38 deletions

File tree

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.12.1-8014
2+
Version: 4.12.1-8015
33
Date: 2026-03-19
44
Title: Fit, Simulate and Diagnose Exponential-Family Models for Networks
55
Authors@R: c(

R/ergm-package.R

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,12 @@ NULL
528528
#' \if{text}{\Sexpr[results=rd,stage=render]{ergm:::.formatProposalsText(ergm:::.buildProposalsList(), keepProposal=TRUE)}}
529529
#' \if{latex}{\Sexpr[results=rd,stage=render]{ergm:::.formatProposalsLatex(ergm:::.buildProposalsList(), keepProposal=TRUE)}}
530530
#'
531-
#' Note that [`.dyads`][.dyads-ergmConstraint] is a meta-constraint, indicating that the proposal supports an arbitrary dyad-level constraint combination.
531+
#' Note that [`.dyads`][.dyads-ergmConstraint] is a meta-constraint,
532+
#' indicating that the proposal supports an arbitrary dyad-level
533+
#' constraint combination. `*` indicates that the proposal is a
534+
#' proposal operator (a proposal that initializes other proposals) and
535+
#' hence can handle any reference distribution (that its sub-proposals
536+
#' can handle) and any hint (that its sub-proposals can).
532537
#'
533538
#' @seealso [`ergm`][ergm-package] package, [`ergm`], [`ergmConstraint`], [`ergmHint`], [`ergm_proposal`]
534539
#'

R/ergm-terms-index.R

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,18 @@ DISPLAY_LATEX_TOC_PCT_WIDTHS <- function(n_concepts) c(2.4, rep(.7, n_concepts))
8080
ps <- ergm_proposal_table()
8181
ps <- .filterProposals(ps, proposal=comps[1])
8282

83-
proposals <- with(ps, map(seq_along(Proposal), function(i) {
84-
list(
85-
Proposal = Proposal[i],
86-
Reference = Reference[i],
87-
Enforces = Constraints[[i]]$does,
88-
May_Enforce = c(Constraints[[i]]$can, if (Constraints[[i]]$can_any) "*"),
89-
Priority = Priority[i],
90-
Weight = Weights[i],
91-
Class = ifelse(Class[i] == "c", "cross-sectional", "last-toggle")
83+
proposals <- with(ps, {
84+
data.frame(
85+
Proposal = Proposal,
86+
Reference = Reference,
87+
Enforces = I(map(Constraints, "does")),
88+
`May Enforce` = I(map(Constraints, \(x) c(x$can, if (x$can_any) "*"))),
89+
Priority = Priority,
90+
Weight = Weights,
91+
Class = ifelse(Class == "c", "cross-sectional", "last-toggle"),
92+
check.names = FALSE
9293
)
93-
}))
94+
})
9495
return(list(
9596
link=rdname,
9697
name=comps[1],
@@ -262,11 +263,10 @@ ergmTermCache <- local({
262263
if (!missing(proposal)) {
263264
proposals <- proposals[[paste0(proposal)]]$rules
264265
} else {
265-
proposals <- proposals %>% map("rules") %>% flatten()
266+
proposals <- proposals |> map("rules") |> do.call(\(...) rbind(..., make.row.names = FALSE), args = _)
266267
}
267268

268-
if (length(proposals) == 0) return(NULL)
269-
names(proposals) <- seq_along(proposals)
269+
if (nrow(proposals) == 0) return(NULL)
270270
proposals
271271
}
272272

@@ -353,16 +353,16 @@ ergmTermCache <- local({
353353
PROPOSAL_NOT_IN_TABLE <- "This proposal is not referenced in the lookup table."
354354

355355
.formatProposalsHtml <- function(df, keepProposal=FALSE) {
356-
if (NROW(df) == 0) return(paste0("\\out{<p>", PROPOSAL_NOT_IN_TABLE, "</p>}"))
356+
if (nrow(df) == 0) return(paste0("\\out{<p>", PROPOSAL_NOT_IN_TABLE, "</p>}"))
357357

358-
for (i in seq_along(df)) {
359-
df[[i]]$Proposal <- sprintf('<a href="../help/%1$s-ergmProposal">%1$s</a>', df[[i]]$Proposal)
360-
df[[i]]$Reference <- sprintf('<a href="../help/%1$s-ergmReference">%1$s</a>', df[[i]]$Reference)
361-
df[[i]]$Enforces <- if (length(df[[i]]$Enforces) > 0) paste(sprintf('<a href="../help/%1$s-ergmConstraint">%1$s</a>', df[[i]]$Enforces), collapse=' ') else ""
362-
df[[i]]$May_Enforce <- if (length(df[[i]]$May_Enforce) > 0) paste(sprintf('<a href="../help/%1$s-ergmConstraint">%1$s</a>', df[[i]]$May_Enforce), collapse=' ') else ""
358+
link_ergmcon <- function(x) {
359+
paste(sprintf('<a href="../help/%1$s-ergmConstraint">%1$s</a>', x), collapse = " ")
363360
}
364361

365-
df <- do.call(rbind.data.frame, df)
362+
df$Proposal <- sprintf('<a href="../help/%1$s-ergmProposal">%1$s</a>', df$Proposal)
363+
df$Reference <- sprintf('<a href="../help/%1$s-ergmReference">%1$s</a>', df$Reference)
364+
df$Enforces <- map_chr(df$Enforces, link_ergmcon)
365+
df$`May Enforce` <- map_chr(df$`May Enforce`, link_ergmcon)
366366

367367
if (!keepProposal) {
368368
df <- df[,colnames(df)!="Proposal"]
@@ -372,16 +372,12 @@ PROPOSAL_NOT_IN_TABLE <- "This proposal is not referenced in the lookup table."
372372
}
373373

374374
.formatProposalsLatex <- function(df, keepProposal=FALSE) {
375-
if (NROW(df) == 0) return(paste0("\\out{",PROPOSAL_NOT_IN_TABLE,"}"))
375+
if (nrow(df) == 0) return(paste0("\\out{",PROPOSAL_NOT_IN_TABLE,"}"))
376376

377-
for (i in seq_along(df)) {
378-
df[[i]]$Enforces <- if (length(df[[i]]$Enforces) > 0) paste(df[[i]]$Enforces, collapse=' ') else ""
379-
df[[i]]$May_Enforce <- if (length(df[[i]]$May_Enforce) > 0) paste(df[[i]]$May_Enforce, collapse=' ') else ""
380-
}
377+
link_ergmcon <- function(x) paste(x, collapse = " ")
381378

382-
df <- as.data.frame(do.call(rbind.data.frame, df))
383-
names(df) <- c('Proposal', 'Reference', 'Enforces', 'May Enforce', 'Priority', 'Weight', 'Class')
384-
df[, 'Class'] = ifelse(df[, 'Class'] == 'cross-sectional', 'c', 't')
379+
df$Enforces <- map_chr(df$Enforces, link_ergmcon)
380+
df$`May Enforce` <- map_chr(df$`May Enforce`, link_ergmcon)
385381

386382
if (!keepProposal) {
387383
df <- df[,colnames(df)!="Proposal"]
@@ -396,12 +392,10 @@ PROPOSAL_NOT_IN_TABLE <- "This proposal is not referenced in the lookup table."
396392
.formatProposalsText <- function(df, keepProposal=FALSE) {
397393
if (NROW(df) == 0) return(PROPOSAL_NOT_IN_TABLE)
398394

399-
for (i in seq_along(df)) {
400-
df[[i]]$Enforces <- if (length(df[[i]]$Enforces) > 0) paste(df[[i]]$Enforces, collapse=' ') else ""
401-
df[[i]]$May_Enforce <- if (length(df[[i]]$May_Enforce) > 0) paste(df[[i]]$May_Enforce, collapse=' ') else ""
402-
}
395+
link_ergmcon <- function(x) paste(x, collapse = " ")
403396

404-
df <- do.call(rbind.data.frame, df)
397+
df$Enforces <- map_chr(df$Enforces, link_ergmcon)
398+
df$`May Enforce` <- map_chr(df$`May Enforce`, link_ergmcon)
405399

406400
if (!keepProposal) {
407401
df <- df[,colnames(df)!="Proposal"]
@@ -881,7 +875,7 @@ search.ergmProposals <- function(search, name, reference, constraints, packages)
881875
for (constraint in constraints) {
882876
for (t in which(found)) {
883877
term <-terms[[t]]
884-
if (!constraint %in% (term$rules %>% map('Enforces') %>% unlist) && !constraint %in% (term$rules %>% map("May_Enforce") %>% unlist)) {
878+
if (!constraint %in% (term$rules %>% map('Enforces') %>% unlist) && !constraint %in% (term$rules %>% map("`May Enforce`") %>% unlist)) {
885879
found[t]<-FALSE
886880
}
887881
}
@@ -918,7 +912,7 @@ search.ergmProposals <- function(search, name, reference, constraints, packages)
918912
rule$Reference,
919913
rule$Class,
920914
if (length(rule$Enforces) > 0) paste(" Enforces:", paste(rule$Enforces, collapse=" "), "\n") else "",
921-
if (length(rule$May_Enforce) > 0) paste(" May Enforce:", paste(rule$May_Enforce, collapse=" "), "\n") else ""))
915+
if (length(rule$`May Enforce`) > 0) paste(" May Enforce:", paste(rule$`May Enforce`, collapse=" "), "\n") else ""))
922916
}
923917
}
924918
}

man/ergmProposal.Rd

Lines changed: 6 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)