Skip to content

Commit

Permalink
more test adjustments and bug fix
Browse files Browse the repository at this point in the history
 - move data path fix to above parsing the control stream. This previously wasnt necessary since we parsed the parent model
  • Loading branch information
barrettk committed Sep 19, 2024
1 parent 47c8301 commit df3566e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
20 changes: 10 additions & 10 deletions R/bootstrap-model.R
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,16 @@ setup_bootstrap_run <- function(
writeLines(ignore_lines, file.path(boot_dir, ".gitignore"))

if(is.null(data)){
# Overwrite data path in control stream
# - This is not necessary in most cases, but is if overwriting a previous
# run where a starting dataset was provided. The data path must then
# be updated to reflect the original control stream
data_path <- get_data_path(.boot_run, .check_exists = FALSE)
if(!fs::file_exists(data_path)){
data_path_rel <- get_data_path_from_ctl(orig_mod, normalize = FALSE)
modify_data_path_ctl(.boot_run, data_path_rel)
}

# Only include subjects that entered the original problem by default
starting_data <- tryCatch({
nm_data(.boot_run, filter = TRUE) %>% suppressMessages()
Expand Down Expand Up @@ -222,16 +232,6 @@ setup_bootstrap_run <- function(
)
)
}

# Overwrite data path in control stream
# - This is not necessary in most cases, but is if overwriting a previous
# run where a starting dataset was provided. The data path must then
# be updated to reflect the original control stream
data_path <- get_data_path(.boot_run, .check_exists = FALSE)
if(!fs::file_exists(data_path)){
data_path_rel <- get_data_path_from_ctl(orig_mod, normalize = FALSE)
modify_data_path_ctl(.boot_run, data_path_rel)
}
}else{
checkmate::assert_data_frame(data)
# Get input columns from dataset referenced in based_on model
Expand Down
13 changes: 5 additions & 8 deletions tests/testthat/test-workflow-bootstrap.R
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ withr::with_options(

# Set filter that should error
data_rec$values[[7]]$value <- "(ID.EQ.2, SEX.EQ.1)"
nmrec::write_ctl(ctl, get_model_path(mod2))
nmrec::write_ctl(ctl, get_model_path(boot_run2))

expect_error(
setup_bootstrap_run(boot_run2, n = 3),
Expand All @@ -172,10 +172,7 @@ withr::with_options(
})

test_that("setup_bootstrap_run works as expected", {
expect_message(
setup_bootstrap_run(.boot_run, n = 3, .overwrite = TRUE, seed = NULL),
"Dropped 20 records from starting data"
)
setup_bootstrap_run(.boot_run, n = 3, .overwrite = TRUE, seed = NULL)

# Check print method - strat_cols are made to be NA if none provided
bullets <- capture.output({
Expand Down Expand Up @@ -422,9 +419,9 @@ withr::with_options(
# Copy model files and output directory of simulation
new_dir <- tempdir()
new_dir_path <- file.path(new_dir, basename(.boot_run[[ABS_MOD_PATH]]))
fs::file_copy(ctl_ext(.boot_run[[ABS_MOD_PATH]]), ctl_ext(new_dir_path))
fs::file_copy(yaml_ext(.boot_run[[ABS_MOD_PATH]]), yaml_ext(new_dir_path))
fs::dir_copy(.boot_run[[ABS_MOD_PATH]], new_dir_path)
fs::file_copy(ctl_ext(.boot_run[[ABS_MOD_PATH]]), ctl_ext(new_dir_path), overwrite = TRUE)
fs::file_copy(yaml_ext(.boot_run[[ABS_MOD_PATH]]), yaml_ext(new_dir_path), overwrite = TRUE)
fs::dir_copy(.boot_run[[ABS_MOD_PATH]], new_dir_path, overwrite = TRUE)
fake_boot <- read_model(new_dir_path)
on.exit(delete_models(fake_boot, .tags = NULL, .force = TRUE))

Expand Down

0 comments on commit df3566e

Please sign in to comment.