@@ -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({
353353PROPOSAL_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 }
0 commit comments