Skip to content

Commit

Permalink
make objects a little thinner for checking (see #48)
Browse files Browse the repository at this point in the history
  • Loading branch information
philchalmers committed Dec 6, 2024
1 parent 55918a6 commit 58bee58
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
12 changes: 8 additions & 4 deletions R/SimCollect.R
Original file line number Diff line number Diff line change
Expand Up @@ -311,16 +311,16 @@ SimCollect <- function(dir=NULL, files = NULL, filename = NULL,
reps_bad <- out$REPLICATIONS != target.reps
if(any(reps_bad)){
diff <- target.reps - out$REPLICATIONS
if(diff < 0)
if(any(diff < 0))
stop('target.reps is less than the number of replications collected',
call.=FALSE)
out$MISSED_REPLICATIONS <- as.integer(diff)
out$TARGET_REPLICATIONS <- as.integer(target.reps)
out$REPLICATIONS <- NULL
message("The following design conditions did not satisfy the target.reps")
message("\nThe following design conditions did not satisfy the target.reps")
return(out[reps_bad,])
} else {
message(c('All replications satisfied target.reps criteria of ', target.reps))
message(c('\nAll replications satisfied target.reps criteria of ', target.reps))
return(invisible(TRUE))
}
}
Expand Down Expand Up @@ -349,10 +349,14 @@ SimCollect <- function(dir=NULL, files = NULL, filename = NULL,
subset_results <- function(obj, select){
if(is.null(select)) return(obj)
res <- attr(obj, 'extra_info')$stored_results
design.names <- attr(obj, 'design')$design
if(length(select) == 1L && select %in% c('NONE', 'REPLICATIONS')){
res <- NULL
if(select != 'NONE')
obj <- dplyr::select(obj, c(design.names, select))
} else {
res <- dplyr::select(res, select)
if(length(select))
obj <- dplyr::select(obj, c(design.names, select))
}
attr(obj, 'extra_info')$stored_results <- res
obj
Expand Down
3 changes: 2 additions & 1 deletion R/SimExtract.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ SimExtract <- function(object, what, fuzzy = TRUE, append = TRUE){
stopifnot(is(object, "SimDesign"))
what <- tolower(what)
pick <- attr(object, 'design_names')$design
Design <- if(any(pick != 'dummy_run'))
Design <- if(any(pick != 'dummy_run') &&
all(names(object) %in% attr(object, 'design_names')$design))
object[,attr(object, 'design_names')$design]
else dplyr::tibble(.rows = nrow(object))
if(what == 'design') return(Design)
Expand Down

0 comments on commit 58bee58

Please sign in to comment.