-
Notifications
You must be signed in to change notification settings - Fork 14
/
debugging.R
39 lines (38 loc) · 1.39 KB
/
debugging.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#' Write simulation event info to file
#'
#' Useful for debugging.
#'
#' @param sim A `simList` object.
#' @param file Character specifying the file name (default \file{"events.txt"}).
#' @param append Logical indicating whether to append to the file (default `FALSE`).
#'
#' @return Nothing returned. Invoked for its side effect of writing to file.
#'
#' @author Alex Chubaty
#' @export
#' @importFrom reproducible normPath
writeEventInfo <- function(sim, file = "events.txt", append = FALSE) {
f <- normPath(file)
curr <- current(sim)
cat(paste(curr$moduleName, curr$eventType, curr$eventTime), ":\n",
file = file, append = append)
}
#' Write RNG state info to file
#'
#' Useful for debugging and ensuring reproducibility.
#'
#' @param file Character specifying the filename (default `"seed.txt"`).
#' @param append Logical indicating whether to append to the file (default `FALSE`).
#'
#' @return Nothing returned. Invoked for its side effect of writing to file.
#'
#' @author Alex Chubaty
#' @export
#' @importFrom reproducible normPath
writeRNGInfo <- function(file = "seed.txt", append = FALSE) {
fseed <- normPath(file)
cat("\tStart of new RNG stream: ", file = fseed, append = append)
## NOTE: the first element of .Random.seed specifies the RNG type, so omit it
cat(.Random.seed[2:11], file = fseed, sep = ", ", append = append)
cat(".", file = fseed, sep = "\n", append = append)
}