1818# ' Note that \code{'warning_seeds'} are not stored automatically in
1919# ' simulations and require passing \code{store_warning_seeds = TRUE} to \code{\link{runSimulation}}.
2020# '
21+ # ' @param fuzzy logical; use fuzzy string matching to reduce effectively identical messages?
22+ # ' For example, when attempting to invert a matrix the error message
23+ # ' \emph{"System is computationally singular: reciprocal condition number = 1.92747e-17"} and
24+ # ' \emph{"System is computationally singular: reciprocal condition number = 2.15321e-16"} are
25+ # ' effectively the same, and likely should be reported in the same columns of the extracted output
26+ # '
2127# ' @export
2228# '
2329# ' @references
7076# '
7177# '
7278# ' }
73- SimExtract <- function (object , what ){
79+ SimExtract <- function (object , what , fuzzy = TRUE ){
7480 stopifnot(is(object , " SimDesign" ))
7581 what <- tolower(what )
7682 pick <- attr(object , ' design_names' )$ design
@@ -82,25 +88,31 @@ SimExtract <- function(object, what){
8288 ret <- if (what == ' results' ){
8389 extract_results(object )
8490 } else if (what == ' errors' ){
85- cbind(Design , extract_errors(object ))
91+ cbind(Design , extract_errors(object , fuzzy = fuzzy ))
8692 } else if (what == ' summarise' ){
8793 extract_summarise(object )
8894 } else if (what == ' error_seeds' ){
8995 extract_error_seeds(object )
9096 } else if (what == ' warnings' ){
91- cbind(Design , extract_warnings(object ))
97+ cbind(Design , extract_warnings(object , fuzzy = fuzzy ))
9298 } else if (what == ' warning_seeds' ){
9399 extract_warning_seeds(object )
94100 } else stop(' Input provided to \" what" is not supported' )
95101 ret
96102}
97103
98- extract_errors <- function (object ){
99- attr(object , ' ERROR_msg' )
104+ extract_errors <- function (object , fuzzy ){
105+ ret <- attr(object , ' ERROR_msg' )
106+ if (fuzzy )
107+ ret <- fuzzy_reduce(ret )
108+ ret
100109}
101110
102- extract_warnings <- function (object ){
103- attr(object , ' WARNING_msg' )
111+ extract_warnings <- function (object , fuzzy ){
112+ ret <- attr(object , ' WARNING_msg' )
113+ if (fuzzy )
114+ ret <- fuzzy_reduce(ret )
115+ ret
104116}
105117
106118extract_results <- function (object ){
@@ -142,3 +154,19 @@ extract_summarise <- function(object){
142154 names(ret ) <- nms
143155 ret
144156}
157+
158+ fuzzy_reduce <- function (df ){
159+ nms <- colnames(df )
160+ matched <- logical (length(nms ))
161+ unames <- c()
162+ udf <- df [,0 ]
163+ for (i in 1L : length(nms )){
164+ if (matched [i ]) next
165+ unames <- c(unames , nms [i ])
166+ udf <- cbind(udf , df [,i ])
167+ temp_matched <- agrepl(nms [i ], nms )
168+ udf [,ncol(udf )] <- rowSums(df [,temp_matched ], na.rm = TRUE )
169+ matched <- matched | temp_matched
170+ }
171+ udf
172+ }
0 commit comments