Skip to content

Commit

Permalink
Give error when tipdating file is not found, progress ropensci/babett…
Browse files Browse the repository at this point in the history
  • Loading branch information
richelbilderbeek committed Jan 4, 2025
1 parent 63c1049 commit 5756127
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
13 changes: 12 additions & 1 deletion R/check_inference_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ check_inference_model <- function(
)
}
)
check_string(inference_model$tipdates_filename, allow_na = TRUE)
if (!is_one_na(inference_model$tipdates_filename)) {
check_string(inference_model$tipdates_filename)
if (!file.exists(inference_model$tipdates_filename)) {
stop(
"Tipdating filename not found at path '",
inference_model$tipdates_filename, "'. \n",
"Tip: set either to NA (i.e. no tip dating) ",
"or to a valid path"
)
}
}

invisible(inference_model)
}
33 changes: 13 additions & 20 deletions tests/testthat/test-babette_issue_108.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,20 @@ test_that("use", {
fasta_filename <- get_beautier_path("babette_issue_108.fasta")
output_filename <- get_beautier_tempfilename()
tipdates_filename <- "TIPDATES_FILENAME"
create_beast2_input_file(
fasta_filename,
output_filename,
tipdates_filename = tipdates_filename,
clock_model = create_rln_clock_model(),
site_model = create_gtr_site_model(),
mcmc = create_mcmc(),
tree_prior = create_cbs_tree_prior(),
beauti_options = create_beauti_options_v2_6()
expect_error(
create_beast2_input_file(
input_filename = fasta_filename,
output_filename,
tipdates_filename = tipdates_filename,
clock_model = create_rln_clock_model(),
site_model = create_gtr_site_model(),
mcmc = create_mcmc(chain_length = 1000),
tree_prior = create_cbs_tree_prior(),
beauti_options = create_beauti_options_v2_6()
),
"Tipdating filename not found at path 'TIPDATES_FILENAME'"
)
expect_equal(
1,
length(
stringr::str_subset(
string = readr::read_lines(output_filename),
pattern = tipdates_filename
)
)
)

expect_true(file.exists(output_filename))
expect_false(file.exists(output_filename))
expect_false(file.exists(tipdates_filename))
remove_beautier_folder()
})

0 comments on commit 5756127

Please sign in to comment.