Skip to content

Commit 1cc78f2

Browse files
committed
use SimRead instead
1 parent 3dc194a commit 1cc78f2

File tree

11 files changed

+75
-26
lines changed

11 files changed

+75
-26
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.24.1
3+
Version: 2.24.2
44
Authors@R: c(person("Phil", "Chalmers", email = "rphilip.chalmers@gmail.com", role = c("aut", "cre"),
55
comment = c(ORCID="0000-0001-5332-2810")),
66
person("Matthew", "Sigal", role = c("ctb")),

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export(SimClean)
4242
export(SimCollect)
4343
export(SimExtract)
4444
export(SimFunctions)
45+
export(SimRead)
4546
export(SimResults)
4647
export(SimShiny)
4748
export(SimSolve)

NEWS.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
## Changes in SimDesign 2.25
44

5-
- Temp files now stored using `qs2` package to reduce overhead (see #83)
5+
- Temp files and other frequently hard-drive written objects
6+
now stored using `qs2` package to reduce overhead (see #83). Relatedly,
7+
the function `SimRead()` has been included to read in the stored object,
8+
switching between `qs2::qd_read()` and `readRDS()` where applicable
69

710

811
## Changes in SimDesign 2.24

R/SimResults.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
#'
33
#' If \code{\link{runSimulation}} was passed the flag \code{save_results = TRUE} then the
44
#' row results corresponding to the \code{design} object will be stored to a suitable
5-
#' sub-directory as individual \code{.rds} files. While users could use \code{\link{readRDS}} directly
5+
#' sub-directory as individual \code{.rds} or \code{qs2} files.
6+
#' While users could use \code{\link{readRDS}} and \code{qs2} directly
67
#' to read these files in themselves, this convenience function will read the desired rows in
78
#' automatically given the returned object
8-
#' from the simulation. Can be used to read in 1 or more \code{.rds} files at once (if more than 1 file
9+
#' from the simulation. Can be used to read in 1 or more files at once (if more than 1 file
910
#' is read in then the result will be stored in a list).
1011
#'
1112
#' @param obj object returned from \code{\link{runSimulation}} where \code{save_results = TRUE}
@@ -56,7 +57,7 @@
5657
#'
5758
#' @author Phil Chalmers \email{rphilip.chalmers@@gmail.com}
5859
#'
59-
#' @seealso \code{\link{descript}}
60+
#' @seealso \code{\link{descript}}, \code{\link{SimRead}}
6061
#'
6162
#' @examples
6263
#'

R/runArraySimulation.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
#' \doi{10.20982/tqmp.16.4.p248}
128128
#'
129129
#' @seealso \code{\link{runSimulation}}, \code{\link{expandDesign}},
130-
#' \code{\link{genSeeds}}, \code{\link{SimCheck}},
130+
#' \code{\link{genSeeds}}, \code{\link{SimCheck}}, \code{\link{SimRead}},
131131
#' \code{\link{SimCollect}}, \code{\link{getArrayID}}
132132
#'
133133
#' @examples
@@ -202,7 +202,7 @@
202202
#' summarise=Summarise, iseed=iseed,
203203
#' filename='mylongsim', arrayID=arrayID)
204204
#'
205-
#' res <- readRDS('mylongsim-14.rds')
205+
#' res <- SimRead('mylongsim-14.rds')
206206
#' res
207207
#' SimResults(res) # condition and replication count stored
208208
#'
@@ -235,7 +235,7 @@
235235
#' # check that all files saved (warnings will be raised if missing files)
236236
#' SimCheck('sim/')
237237
#'
238-
#' condition14 <- readRDS('sim/condition-14.rds')
238+
#' condition14 <- SimRead('sim/condition-14.rds')
239239
#' condition14
240240
#' SimResults(condition14)
241241
#'
@@ -286,7 +286,7 @@
286286
#'
287287
#' # note that all row conditions are still stored separately, though note that
288288
#' # arrayID is now 2 instead
289-
#' condition14 <- readRDS('sim/condition-14.rds')
289+
#' condition14 <- SimRead('sim/condition-14.rds')
290290
#' condition14
291291
#' SimResults(condition14)
292292
#'

R/runSimulation.R

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,8 @@
345345
#' Each saved object will contain a list of three elements containing the
346346
#' condition (row from \code{design}),
347347
#' results (as a \code{list} or \code{matrix}), and try-errors.
348-
#' See \code{\link{SimResults}} for an example of how to read these \code{.rds} files back into R
348+
#' See \code{\link{SimResults}} and \code{\link{SimRead}}
349+
#' for an example of how to read these \code{.rds} files back into R
349350
#' after the simulation is complete. Default is \code{FALSE}.
350351
#'
351352
#' WARNING: saving results to your hard-drive can fill up space very quickly for
@@ -564,7 +565,7 @@
564565
#' in the current working directory then a unique one will be created automatically. Default is
565566
#' \code{'SimDesign-results_'} with the associated \code{compname} appended if no
566567
#' \code{filename} is defined, otherwise the filename is used to replace 'SimDesign'
567-
#' in the string}
568+
#' in the string. See \code{\link{SimRead}} to read in the individual files}
568569
#'
569570
#' \item{\code{save_results_filename}}{a string indicating the name file to store, where the
570571
#' \code{Design} row ID will be appended to ensure uniqueness across rows. Specifying
@@ -575,7 +576,8 @@
575576
#' for HPC structures that allow asynchronous file storage).
576577
#' WARNING: the uniqueness of the file names are not checked using
577578
#' this approach, therefore please ensure that each generated name will be unique a priori,
578-
#' such as naming the file based on the supplied row condition information}
579+
#' such as naming the file based on the supplied row condition information.
580+
#' See \code{\link{SimRead}} to read in the individual files}
579581
#'
580582
#' \item{\code{save_seeds_dirname}}{a string indicating the name of the folder to save
581583
#' \code{.Random.seed} objects to when \code{save_seeds = TRUE}. If a directory/folder
@@ -617,7 +619,8 @@
617619
#' To recover your simulation at the last known location (having patched the issues in the
618620
#' previous execution code) simply re-run the code you used to
619621
#' initially define the simulation and the external file will automatically be detected and read-in.
620-
#' Default is \code{TRUE} when \code{replications > 10} and \code{FALSE} otherwise
622+
#' Default is \code{TRUE} when \code{replications > 10} and \code{FALSE} otherwise.
623+
#' See also \code{\link{SimRead}} to read and inspect the stored files
621624
#'
622625
#' @param resume logical; if a temporary \code{SimDesign} file is detected should
623626
#' the simulation resume from this location? Keeping this \code{TRUE} is generally recommended,
@@ -735,7 +738,7 @@
735738
#' \code{\link{Generate}}, \code{\link{Analyse}}, \code{\link{Summarise}},
736739
#' \code{\link{SimExtract}},
737740
#' \code{\link{reSummarise}}, \code{\link{SimClean}}, \code{\link{SimAnova}}, \code{\link{SimResults}},
738-
#' \code{\link{SimCollect}}, \code{\link{Attach}}, \code{\link{AnalyseIf}},
741+
#' \code{\link{SimCollect}}, \code{\link{SimRead}}, \code{\link{Attach}}, \code{\link{AnalyseIf}},
739742
#' \code{\link{SimShiny}}, \code{\link{manageWarnings}}, \code{\link{runArraySimulation}}
740743
#'
741744
#' @export runSimulation

R/util.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,20 @@ add_cbind <- function(lst){
10521052
dplyr::as_tibble(ret)
10531053
}
10541054

1055+
1056+
#' Read simulation files
1057+
#'
1058+
#' Convenience function that switches between \code{readRDS()} and
1059+
#' \code{qs2::qs_read()} for functions saved with \code{SimDesign}.
1060+
#' By convention, objects saved with the extension \code{.rds} are read
1061+
#' as R binary files and typically reflect the final object from
1062+
#' \code{\link{runSimulation}} or \code{\link{runArraySimulation}},
1063+
#' while files without an extension are read using \code{qs2} (most often
1064+
#' temporary files or results written to an associated sub-directory).
1065+
#'
1066+
#' @export
1067+
#' @return the R binary object
1068+
#' @param filename name of the file to read in
10551069
SimRead <- function(filename){
10561070
file_ext <- tools::file_ext(filename)
10571071
tmp <- if(tolower(file_ext) == 'rds')

man/SimRead.Rd

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

man/SimResults.Rd

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

man/runArraySimulation.Rd

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

0 commit comments

Comments
 (0)