|
1 |
| -#' Check the status of the simulation's temporary results |
| 1 | +#' Check for missing files in array simulations |
2 | 2 | #'
|
3 |
| -#' This function reads the temporary file saved by \code{\link{runSimulation}} |
4 |
| -#' by collapsing the information into a suitable (albeit temporary) object of |
5 |
| -#' class \code{'SimDesign'}. This is useful when taking a quick-peak at how the |
6 |
| -#' early simulation results are performing (useful long running simulation |
7 |
| -#' results with many rows in the \code{Design} object). Returns a tibble-based |
8 |
| -#' data.frame object (\code{tbl_df}). |
| 3 | +#' Given the saved files from a \code{\link{runArraySimulation}} remote |
| 4 | +#' evaluation check whether all \code{.rds} files have been saved. If missing |
| 5 | +#' the missing row condition numbers will be returned |
9 | 6 | #'
|
10 |
| -#' @param file the temp file currently saving the simulation state. If missing |
11 |
| -#' the file is assumed to be in the current working directory, and start with the |
12 |
| -#' name \code{'SIMDESIGN-TEMPFILE'} |
| 7 | +#' @param files vector of file names referring to the saved simulation files. |
| 8 | +#' E.g. \code{c('mysim-1.rds', 'mysim-2.rds', ...)} |
13 | 9 | #'
|
14 |
| -#' @seealso \code{\link{runSimulation}} |
| 10 | +#' @param min minimum number after the \code{'-'} deliminator. Default is 1 |
| 11 | +#' |
| 12 | +#' @param max maximum number after the \code{'-'} deliminator. If not specified |
| 13 | +#' is taken to be the highest number of the \code{files} input |
| 14 | +#' |
| 15 | +#' @seealso \code{\link{runArraySimulation}} |
15 | 16 | #'
|
16 | 17 | #' @references
|
17 | 18 | #'
|
18 | 19 | #' Chalmers, R. P., & Adkins, M. C. (2020). Writing Effective and Reliable Monte Carlo Simulations
|
19 | 20 | #' with the SimDesign Package. \code{The Quantitative Methods for Psychology, 16}(4), 248-280.
|
20 | 21 | #' \doi{10.20982/tqmp.16.4.p248}
|
21 | 22 | #'
|
22 |
| -#' Sigal, M. J., & Chalmers, R. P. (2016). Play it again: Teaching statistics with Monte |
23 |
| -#' Carlo simulation. \code{Journal of Statistics Education, 24}(3), 136-156. |
24 |
| -#' \doi{10.1080/10691898.2016.1246953} |
25 |
| -#' |
26 | 23 | #' @export
|
27 | 24 | #'
|
28 | 25 | #' @author Phil Chalmers \email{rphilip.chalmers@@gmail.com}
|
29 | 26 | #'
|
30 | 27 | #' @examples
|
31 | 28 | #' \dontrun{
|
32 | 29 | #'
|
33 |
| -#' # explicit |
34 |
| -#' temp_results <- SimCheck(file = 'SIMDESIGN-TEMPFILE_mycomp.rds') |
35 |
| -#' temp_results |
36 |
| -#' |
37 |
| -#' # works if file is in the current working directory |
38 |
| -#' temp_results <- SimCheck() |
39 |
| -#' temp_results |
| 30 | +#' setwd('mysimfiles/') |
| 31 | +#' files <- dir() |
| 32 | +#' SimCheck() |
40 | 33 | #'
|
41 | 34 | #' }
|
42 | 35 | #'
|
43 |
| -SimCheck <- function(file){ |
44 |
| - pat <- 'SIMDESIGN-TEMPFILE' |
45 |
| - input <- if(missing(file)){ |
46 |
| - files <- dir() |
47 |
| - pick <- grepl(pat, files) |
48 |
| - if(!any(pick)){ |
49 |
| - message("No temporary file found") |
50 |
| - return(invisible(NULL)) |
51 |
| - } |
52 |
| - readRDS(files[pick][1L]) |
53 |
| - } else { |
54 |
| - if(!file.exists(file)){ |
55 |
| - message("file name does not exist") |
56 |
| - return(invisible(NULL)) |
57 |
| - } |
58 |
| - readRDS(file) |
| 36 | +SimCheck <- function(files, min = 1L, max = NULL){ |
| 37 | + filename <- strsplit(files[1], '-')[[1L]][1L] |
| 38 | + if(is.null(max)){ |
| 39 | + subfiles <- gsub(paste0(filename, '-'), files, replacement = '') |
| 40 | + subfiles <- gsub('.rds', subfiles, replacement = '') |
| 41 | + max <- max(as.integer(subfiles)) |
59 | 42 | }
|
60 |
| - ret <- dplyr::as_tibble(dplyr::bind_rows(input)) |
61 |
| - ret <- subset(ret, select = !(names(ret) %in% c('ID', 'REPLICATION'))) |
62 |
| - ret |
| 43 | + minmax <- min:max |
| 44 | + notin <- !(paste0(filename, '-', minmax, '.rds') %in% files) |
| 45 | + if(any(notin)){ |
| 46 | + cat(sprintf('The following row conditions were missing:\n%s', |
| 47 | + paste0(minmax[notin], collapse=','))) |
| 48 | + } else |
| 49 | + cat(sprintf('No missing conditions from %i to %i were detected', min, max)) |
| 50 | + invisible(NULL) |
63 | 51 | }
|
0 commit comments