Skip to content

Commit 23005fc

Browse files
committed
add SUMMARISE column when needed
1 parent 5717f74 commit 23005fc

File tree

7 files changed

+39
-28
lines changed

7 files changed

+39
-28
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: SimDesign
22
Title: Structure for Organizing Monte Carlo Simulation Designs
3-
Version: 2.19.2
3+
Version: 2.19.3
44
Authors@R: c(person("Phil", "Chalmers", email = "[email protected]", role = c("aut", "cre"),
55
comment = c(ORCID="0000-0001-5332-2810")),
66
person("Matthew", "Sigal", role = c("ctb")),

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# NEWS file for SimDesign
22

3+
## Changes in SimDesign 2.20
4+
5+
- When `summarise()` returns a `list` this information is now stored in a column
6+
`SUMMARISE` in the final simulation object. This replaces the previous
7+
`SimExtract()` approach to index the same information
8+
39
## Changes in SimDesign 2.19.1
410

511
- `print.Design()` gains a `show.IDs` flag to show the internally stored condition

R/SimExtract.R

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@
1616
#' \code{'error_seeds'} and \code{'warning_seeds'}
1717
#' to extract the associated \code{.Random.seed} values associated with the ERROR/WARNING messages,
1818
#' \code{'results'} to extract the simulation results if the option \code{store_results} was passed to
19-
#' \code{\link{runSimulation}}, \code{'filename'} and \code{'save_results_dirname'} for extracting
20-
#' the saved file/directory name information (if used),
21-
#' and \code{'summarise'} if the \code{\link{Summarise}}
22-
#' definition returned a named \code{list} rather than a named numeric vector.
19+
#' \code{\link{runSimulation}}, and \code{'filename'} and \code{'save_results_dirname'} for extracting
20+
#' the saved file/directory name information (if used)
2321
#'
2422
#' Note that \code{'warning_seeds'} are not stored automatically in
2523
#' simulations and require passing \code{store_warning_seeds = TRUE} to \code{\link{runSimulation}}.
@@ -181,16 +179,6 @@ extract_seeds <- function(object){
181179
ret
182180
}
183181

184-
extract_summarise <- function(object){
185-
extra_info <- attr(object, 'extra_info')
186-
Design <- SimExtract(object, 'Design')
187-
nms <- apply(Design, 1L, function(x)
188-
paste0(colnames(Design), "=", x, collapse = ' ; '))
189-
ret <- extra_info$summarise_list
190-
names(ret) <- nms
191-
ret
192-
}
193-
194182
fuzzy_reduce <- function(df){
195183
if(!length(df)) return(df)
196184
nms <- colnames(df)

R/runSimulation.R

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@
158158
#' each \code{design} condition. Return of this function, in order
159159
#' of increasing complexity, should be: a named numeric vector or \code{data.frame}
160160
#' with one row, a \code{matrix} or \code{data.frame} with more than one row, and,
161-
#' failing these more atomic types, a named \code{list}. For summary objects that
162-
#' are not easily appended to the original \code{design} object use
163-
#' \code{\link{SimExtract}} with the option \code{what = 'summarise'}.
161+
#' failing these more atomic types, a named \code{list}. When a \code{list} is returned
162+
#' the final simulation object will contain a column \code{SUMMARISE} containing the
163+
#' summary results for each respective condition
164164
#'
165165
#' Note that unlike the Generate and Analyse
166166
#' steps, the Summarise portion is not as important to perfectly organize
@@ -1663,10 +1663,14 @@ runSimulation <- function(design, replications, generate, analyse, summarise,
16631663
if(!is.null(Final$REPLICATIONS)) replications <- Final$REPLICATIONS
16641664
Final$SIM_TIME <- Final$ID <- Final$COMPLETED <-
16651665
Final$REPLICATIONS <- Final$REPLICATION <- Final$FATAL_TERMINATION <- NULL
1666+
SUMMARISE <- if(any(!sapply(summarise_list, is.null))){
1667+
summarise_list
1668+
} else rep(NA, nrow(Final))
16661669
Final <- data.frame(Final, FATAL_TERMINATION,
16671670
REPLICATIONS=replications, SIM_TIME=SIM_TIME,
16681671
RAM_USED=memory_used,
16691672
COMPLETED, check.names=FALSE, stringsAsFactors=FALSE)
1673+
if(!all(is.na(SUMMARISE))) Final$SUMMARISE <- SUMMARISE
16701674
if(all(is.na(Final$FATAL_TERMINATION))) Final$FATAL_TERMINATION <- NULL
16711675
if(is.null(Final$SEED)) Final$SEED <- NA
16721676
if(!is.null(seed)) Final$SEED <- seed
@@ -1718,9 +1722,7 @@ runSimulation <- function(design, replications, generate, analyse, summarise,
17181722
error_seeds=dplyr::as_tibble(error_seeds),
17191723
warning_seeds=dplyr::as_tibble(warning_seeds),
17201724
stored_results = if(store_results) stored_Results_list else NULL,
1721-
summarise_list=summarise_list, Design.ID=Design.ID)
1722-
if(!is.null(summarise_list[[1L]]) && verbose)
1723-
message('Note: To extract Summarise() results use SimExtract(., what = \'summarise\')')
1725+
Design.ID=Design.ID)
17241726
if(dummy_run) Final$dummy_run <- NULL
17251727
class(Final) <- c('SimDesign', class(Final))
17261728
if(!is.null(filename)){ #save file

man/SimExtract.Rd

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/runSimulation.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/tests/test-01-core.R

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,27 @@ test_that('SimDesign', {
6666
return(ret)
6767
}
6868

69+
mycollect_list <- function(condition, results, fixed_objects){
70+
71+
#find results of interest here
72+
nms <- c('welch', 'independent')
73+
lessthan.05 <- EDR(results[,nms], alpha = .05)
74+
75+
# return the results that will be appended to the Design input
76+
ret <- list(lessthan.05=lessthan.05, something=42)
77+
return(ret)
78+
}
79+
6980
Final <- runSimulation(Design, generate=mysim, analyse=mycompute, summarise=mycollect,
7081
replications = 2, parallel=FALSE, save=FALSE, verbose = FALSE)
7182
expect_is(Final, 'data.frame')
7283

84+
# list in summarise
85+
Final <- runSimulation(Design, generate=mysim, analyse=mycompute, summarise=mycollect_list,
86+
replications = 2, parallel=FALSE, save=FALSE, verbose = FALSE)
87+
expect_is(Final, 'data.frame')
88+
expect_is(Final$SUMMARISE, 'list')
89+
7390
mycollect <- function(condition, results, fixed_objects){
7491

7592
# return the results that will be appended to the Design input

0 commit comments

Comments
 (0)