Skip to content

Commit

Permalink
Merge pull request #22 from ohexel/fix-issue-21
Browse files Browse the repository at this point in the history
Make `create_sup_file()` actually use the argument `simname` (fix issue #21)
  • Loading branch information
tomthe authored Dec 4, 2024
2 parents 07362fa + 0b07205 commit 0421ebf
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions R/startsocsim.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ socsim <- function(folder, supfile, seed = "42", process_method = "inprocess",
print(paste("RNG seed:", seed))
previous_wd = getwd()
result = NULL
# If 'supfile' contains more than a basename, startSocsimWithFile() will
# crash. This is only a workaround.
remove_supfile <- FALSE
if (!identical(basename(supfile), supfile)) {
if (identical(dirname(supfile), "folder")) {
supfile <- basename(supfile)
} else {
warning("The argument 'supfile' contained more than a basename. We copy the .sup file to the 'folder' directory (to avoid startSocsimWithFile() from crashing) and will remove it after the simulation finishes.")
file.copy(from = file.path(folder, supfile), to = folder, overwrite = TRUE)
remove_supfile <- TRUE
}
}
tryCatch(expr = {
setwd(folder)
result = run_sim_w_file(supfile = supfile,
Expand Down Expand Up @@ -233,11 +245,14 @@ run
"
sup_fn <- "socsim.sup"
cat(sup_content, file = file.path(simdir, sup_fn))
fn_SWEfert2022_source <- system.file("extdata", "SWEfert2022", package = "rsocsim", mustWork = TRUE)
fn_SWEfert2022_source <- system.file("extdata", "SWEfert2022",
package = "rsocsim", mustWork = TRUE)
fn_SWEfert2022_dest <- file.path(simdir, "SWEfert2022")
fn_SWEmort2022_source <- system.file("extdata", "SWEmort2022", package = "rsocsim", mustWork = TRUE)
fn_SWEmort2022_source <- system.file("extdata", "SWEmort2022",
package = "rsocsim", mustWork = TRUE)
fn_SWEmort2022_dest <- file.path(simdir, "SWEmort2022")
fn_init_source <- system.file("extdata", "init_new.opop", package = "rsocsim", mustWork = TRUE)
fn_init_source <- system.file("extdata", "init_new.opop",
package = "rsocsim", mustWork = TRUE)
fn_init_dest <- file.path(simdir, "init_new.opop")
file.copy(fn_SWEfert2022_source, fn_SWEfert2022_dest)
file.copy(fn_SWEmort2022_source, fn_SWEmort2022_dest)
Expand Down

0 comments on commit 0421ebf

Please sign in to comment.