Skip to content

Commit

Permalink
Simplify dependencies and don't use testthat in code (as it is sugges…
Browse files Browse the repository at this point in the history
…ts, not Imports.)
  • Loading branch information
olivroy committed Oct 26, 2023
1 parent 2b8f7ca commit 8d603a9
Show file tree
Hide file tree
Showing 34 changed files with 113 additions and 72 deletions.
4 changes: 1 addition & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,15 @@ Imports:
rappdirs,
readr,
rJava,
rlang (>= 1.1.0),
sessioninfo,
stringr,
tibble,
xml2
Suggests:
hunspell,
knitr,
markdown,
rmarkdown,
spelling,
testit,
testthat (>= 2.1.0),
tracerer (>= 2.2.3)
URL: https://docs.ropensci.org/beastier/ (website)
Expand Down
2 changes: 1 addition & 1 deletion R/are_beast2_input_lines.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ are_beast2_input_lines <- function(
file.remove(filename)
return(is_valid)
} else {
testit::assert(method == "fast")
check_true(method == "fast")
return(
are_beast2_input_lines_fast(lines) # nolint internal function
)
Expand Down
6 changes: 3 additions & 3 deletions R/check_beast2_options.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ check_beast2_options_names <- function( # nolint long function name indeed, whic
check_beast2_options_data_types <- function( # nolint long function name indeed, which is fine for an internal function
beast2_options
) {
testthat::expect_true(beautier::is_one_string(beast2_options$input_filename))
testthat::expect_true(beautier::is_one_string(beast2_options$output_state_filename))
check_true(beautier::is_one_string(beast2_options$input_filename))
check_true(beautier::is_one_string(beast2_options$output_state_filename))
check_rng_seed(beast2_options$rng_seed)
check_n_threads(beast2_options$n_threads)
if (!beautier::is_one_bool(beast2_options$use_beagle)) {
Expand All @@ -77,7 +77,7 @@ check_beast2_options_data_types <- function( # nolint long function name indeed,
if (!beautier::is_one_bool(beast2_options$overwrite)) {
stop("'overwrite' must be one boolean")
}
testthat::expect_true(beautier::is_one_string(beast2_options$beast2_path))
check_true(beautier::is_one_string(beast2_options$beast2_path))
if (!beautier::is_one_bool(beast2_options$verbose)) {
stop("'verbose' must be one boolean")
}
Expand Down
4 changes: 2 additions & 2 deletions R/check_can_create_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ check_can_create_file <- function(
} else {
# Delete the file
file.remove(filename)
testthat::expect_true(
check_true(
!file.exists(filename),
info = paste0(
"Cannot delete the file already present at location ", filename
Expand Down Expand Up @@ -58,7 +58,7 @@ check_can_create_file <- function(
}


testthat::expect_true(
check_true(
!file.exists(filename),
info = paste0(
"Cannot delete the temporary file created at location ", filename
Expand Down
6 changes: 3 additions & 3 deletions R/check_can_create_screenlog_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ check_can_create_screenlog_file <- function( # nolint indeed a long function nam
beast2_options
) {
# Extract the screenlog file
testthat::expect_true(file.exists(beast2_options$input_filename))
check_true(file.exists(beast2_options$input_filename))
text <- readr::read_lines(beast2_options$input_filename, progress = FALSE)
screenlog_line <- stringr::str_subset(
string = text,
pattern = "<logger id=\"screenlog\""
)
testthat::expect_equal(length(screenlog_line), 1)
check_true(length(screenlog_line) == 1)
matches <- stringr::str_match(
string = screenlog_line,
pattern = "fileName=\\\"([:graph:]+)\\\" "
)
testthat::expect_equal(ncol(matches), 2)
check_true(ncol(matches) == 2)
screenlog_filename <- matches[1, 2]

if (is.na(screenlog_filename)) return()
Expand Down
2 changes: 1 addition & 1 deletion R/check_can_create_tracelog_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
check_can_create_tracelog_file <- function(
beast2_options
) {
testthat::expect_true(file.exists(beast2_options$input_filename))
check_true(file.exists(beast2_options$input_filename))
tracelog_filename <- extract_tracelog_filename_from_beast2_input_file( # nolint indeed a long internal function name
input_filename = beast2_options$input_filename
)
Expand Down
2 changes: 1 addition & 1 deletion R/check_can_create_treelog_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ check_can_create_treelog_file <- function(
beast2_options
) {
# Extract the treelog file
testthat::expect_true(file.exists(beast2_options$input_filename))
check_true(file.exists(beast2_options$input_filename))
treelog_filename <- extract_treelog_filename_from_beast2_input_file(
input_filename = beast2_options$input_filename
)
Expand Down
2 changes: 1 addition & 1 deletion R/check_rng_seed.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ check_rng_seed <- function(rng_seed) {
"Actual value: ", rng_seed
)
}
testthat::expect_true(beautier::is_one_int(rng_seed))
check_true(beautier::is_one_int(rng_seed))
if (rng_seed <= 0) {
stop(
"'rng_seed' should be one NA or one non-zero positive value.\n",
Expand Down
43 changes: 43 additions & 0 deletions R/check_true_false.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Created by modifying check_bool from import-standalone-type-check.
check_true <- function(x,
...,
allow_na = FALSE,
allow_null = FALSE,
arg = caller_arg(x),
call = caller_env()) {

if (!missing(x) && !isFALSE(x) &&.standalone_types_check_dot_call(ffi_standalone_is_bool_1.0.7, x, allow_na, allow_null)) {
return(invisible(NULL))
}

stop_input_type(
x,
c("`TRUE`"),
...,
allow_na = allow_na,
allow_null = allow_null,
arg = arg,
call = call
)
}
# Adapted from standalone-types-check.R
check_false <- function(x,
...,
allow_na = FALSE,
allow_null = FALSE,
arg = caller_arg(x),
call = caller_env()) {
if (!missing(x) && !isTRUE(x) && .standalone_types_check_dot_call(ffi_standalone_is_bool_1.0.7, x, allow_na, allow_null)) {
return(invisible(NULL))
}

stop_input_type(
x,
c("`FALSE`"),
...,
allow_na = allow_na,
allow_null = allow_null,
arg = arg,
call = call
)
}
6 changes: 3 additions & 3 deletions R/continue_beast2.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ continue_beast2 <- function(
)
# This assumpion should have been proven to be valid
# by check_can_create_dir_for_state_output_file
testthat::expect_true(dir.exists(output_folder))
check_true(dir.exists(output_folder))

##############################################################################
# Run BEAST2
Expand All @@ -77,7 +77,7 @@ continue_beast2 <- function(
stderr = TRUE
)
# If the output is only 1 line, this will probably be an error message
testthat::expect_true(
check_true(
length(output) != 1,
info = paste0(
"Command '", paste0(cmd, collapse = " "), "' failed ",
Expand All @@ -89,7 +89,7 @@ continue_beast2 <- function(
# The files as created by BEAST2
##############################################################################
# This is only true if there has been one sampling event in the MCMC
testthat::expect_true(
check_true(
file.exists(beast2_options$output_state_filename),
info = paste0(
"BEAST2 state file not created after a continued run. \n",
Expand Down
12 changes: 6 additions & 6 deletions R/create_beast2_continue_cmd_from_options.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#' @export
create_beast2_continue_cmd_from_options <- function(beast2_options) { # nolint indeed a long function name
check_beast2_options(beast2_options)
testit::assert(file.exists(beast2_options$beast2_path))
testit::assert(file.exists(get_default_java_path()))
check_true(file.exists(beast2_options$beast2_path))
check_true(file.exists(get_default_java_path()))
cmds <- NULL
if (is_jar_path(beast2_options$beast2_path)) {
cmds <- c(
Expand All @@ -27,13 +27,13 @@ create_beast2_continue_cmd_from_options <- function(beast2_options) { # nolint i
add_quotes_if_has_spaces(beast2_options$beast2_path),
get_beast2_main_class_name()
)
testit::assert(file.exists(cmds[1]))
# Cannot do: testit::assert(file.exists(cmds[3]))
check_true(file.exists(cmds[1]))
# Cannot do: check_true(file.exists(cmds[3]))
# because that path is quotes
# and file.exists does not know what to do with that
} else {
testit::assert(is_bin_path(beast2_options$beast2_path))
testit::assert(file.exists(beast2_options$beast2_path))
check_true(is_bin_path(beast2_options$beast2_path))
check_true(file.exists(beast2_options$beast2_path))
cmds <- add_quotes_if_has_spaces(beast2_options$beast2_path)
}
if (!beautier::is_one_na(beast2_options$rng_seed)) {
Expand Down
4 changes: 2 additions & 2 deletions R/create_beast2_screenlog_folder.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#' @export
create_beast2_screenlog_folder <- function(beast2_options) {
# Extract the screenlog file
testthat::expect_true(file.exists(beast2_options$input_filename))
check_true(file.exists(beast2_options$input_filename))
screenlog_filename <- extract_screenlog_filename_from_beast2_input_file( # nolint indeed a long line
input_filename = beast2_options$input_filename
)
Expand All @@ -19,7 +19,7 @@ create_beast2_screenlog_folder <- function(beast2_options) {
showWarnings = FALSE,
recursive = TRUE
)
testthat::expect_true(
check_true(
dir.exists(dirname(screenlog_filename))
)
invisible(beast2_options)
Expand Down
4 changes: 2 additions & 2 deletions R/create_beast2_tracelog_folder.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#' @export
create_beast2_tracelog_folder <- function(beast2_options) {
# Extract the tracelog file
testthat::expect_true(file.exists(beast2_options$input_filename))
check_true(file.exists(beast2_options$input_filename))
tracelog_filename <- extract_tracelog_filename_from_beast2_input_file( # nolint indeed a long line
input_filename = beast2_options$input_filename
)
Expand All @@ -15,7 +15,7 @@ create_beast2_tracelog_folder <- function(beast2_options) {
showWarnings = FALSE,
recursive = TRUE
)
testthat::expect_true(
check_true(
dir.exists(dirname(tracelog_filename))
)
invisible(beast2_options)
Expand Down
4 changes: 2 additions & 2 deletions R/create_beast2_treelog_folder.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#' @export
create_beast2_treelog_folder <- function(beast2_options) {
# Extract the treelog file
testthat::expect_true(file.exists(beast2_options$input_filename))
check_true(file.exists(beast2_options$input_filename))
treelog_filename <- extract_treelog_filename_from_beast2_input_file(
input_filename = beast2_options$input_filename
)
Expand All @@ -15,7 +15,7 @@ create_beast2_treelog_folder <- function(beast2_options) {
showWarnings = FALSE,
recursive = TRUE
)
testthat::expect_true(
check_true(
dir.exists(dirname(treelog_filename))
)
invisible(beast2_options)
Expand Down
10 changes: 5 additions & 5 deletions R/create_beast2_validate_cmd.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ create_beast2_validate_cmd <- function(
beast2_jar_path = beast2_path
)
} else {
testit::assert(is_bin_path(beast2_path))
check_true(is_bin_path(beast2_path))
create_beast2_validate_cmd_bin(
input_filename = input_filename,
beast2_bin_path = beast2_path
Expand Down Expand Up @@ -58,7 +58,7 @@ create_beast2_validate_cmd_jar <- function(
beast2_jar_path = get_default_beast2_jar_path()
) {
beautier::check_file_exists(beast2_jar_path, "beast2_jar_path")
testit::assert(is_jar_path(beast2_jar_path))
check_true(is_jar_path(beast2_jar_path))
cmds <- c(
get_default_java_path(),
"-cp",
Expand All @@ -68,7 +68,7 @@ create_beast2_validate_cmd_jar <- function(
add_quotes_if_has_spaces(input_filename)
)
# The executable must be runnable. This means that it should not have quotes
testthat::expect_true(file.exists(cmds[1]))
check_true(file.exists(cmds[1]))
cmds
}

Expand Down Expand Up @@ -96,13 +96,13 @@ create_beast2_validate_cmd_bin <- function(
beast2_bin_path = get_default_beast2_bin_path()
) {
beautier::check_file_exists(beast2_bin_path, "beast2_bin_path")
testit::assert(is_bin_path(beast2_bin_path))
check_true(is_bin_path(beast2_bin_path))
cmds <- c(
beast2_bin_path,
"-validate",
add_quotes_if_has_spaces(input_filename)
)
# The executable must be runnable. This means that it should not have quotes
testthat::expect_true(file.exists(cmds[1]))
check_true(file.exists(cmds[1]))
cmds
}
6 changes: 3 additions & 3 deletions R/create_beast2_version_cmd.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ create_beast2_version_cmd <- function(
beast2_jar_path = beast2_path
)
} else {
testit::assert(is_bin_path(beast2_path))
check_true(is_bin_path(beast2_path))
create_beast2_version_cmd_bin(
beast2_bin_path = beast2_path
)
Expand All @@ -42,7 +42,7 @@ create_beast2_version_cmd_jar <- function(
beast2_jar_path = get_default_beast2_jar_path()
) {
beautier::check_file_exists(beast2_jar_path, "beast2_jar_path")
testit::assert(is_jar_path(beast2_jar_path))
check_true(is_jar_path(beast2_jar_path))
cmds <- c(
get_default_java_path(),
"-cp",
Expand Down Expand Up @@ -71,7 +71,7 @@ create_beast2_version_cmd_bin <- function(
beast2_bin_path = get_default_beast2_bin_path()
) {
beautier::check_file_exists(beast2_bin_path, "beast2_bin_path")
testit::assert(is_bin_path(beast2_bin_path))
check_true(is_bin_path(beast2_bin_path))
cmds <- c(
beast2_bin_path,
"-version"
Expand Down
2 changes: 1 addition & 1 deletion R/create_mcbette_beast2_options.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ create_mcbette_beast2_options <- function(
beast2_bin_path = get_default_beast2_bin_path(),
verbose = FALSE
) {
testit::assert(is_bin_path(beast2_bin_path))
check_true(is_bin_path(beast2_bin_path))
create_beast2_options(
input_filename = input_filename,
output_state_filename = output_state_filename,
Expand Down
4 changes: 2 additions & 2 deletions R/create_random_fasta.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ create_random_fasta <- function(
if (sequence_length < 1) {
stop("'sequence_length' must be one or more")
}
testthat::expect_true(beautier::is_one_string(fasta_filename))
check_true(beautier::is_one_string(fasta_filename))

if (fasta_filename == "") {
stop("'fasta_filename' must have at least one character")
}
testthat::expect_true(beautier::is_one_string(taxa_name_ext))
check_true(beautier::is_one_string(taxa_name_ext))
alignments <- create_random_alignment(
n_taxa,
sequence_length,
Expand Down
4 changes: 2 additions & 2 deletions R/extract_screenlog_filename_from_beast2_input_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
extract_screenlog_filename_from_beast2_input_file <- function( # nolint indeed a long function name
input_filename
) {
testthat::expect_true(file.exists(input_filename))
check_true(file.exists(input_filename))
text <- readr::read_lines(input_filename, progress = FALSE)
screenlog_line <- stringr::str_subset(
string = text,
pattern = "<logger id=\"screenlog"
)
testthat::expect_equal(length(screenlog_line), 1)
check_true(length(screenlog_line) == 1)
screenlog_filename <- stringr::str_match(
string = screenlog_line,
pattern = "fileName=\\\"([:graph:]+)\\\" "
Expand Down
Loading

0 comments on commit 8d603a9

Please sign in to comment.