Skip to content

Commit

Permalink
EOD
Browse files Browse the repository at this point in the history
  • Loading branch information
richelbilderbeek committed Mar 14, 2018
1 parent 88d2573 commit a0a7efe
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
2 changes: 1 addition & 1 deletion R/install_beast2.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#' @note This function only tested to work under GNU/Linux
#' @export
install_beast2 <- function(folder_name) {
dir.create(path = folder_name, recursive = TRUE)
dir.create(path = folder_name, showWarnings = FALSE, recursive = TRUE)
tgz_filename <- "BEAST.v2.4.7.Linux.tgz"
url <- paste0(
"https://github.com/CompEvol/beast2/releases/download/v2.4.7/",
Expand Down
24 changes: 20 additions & 4 deletions R/is_beast2_input_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
#' @param beast2_jar_path the path of \code{beast.jar}.
#' Use \link{get_default_beast2_jar_path} to get
#' the default BEAST jar file's path
#' @param show_warnings if TRUE, warnings will shown
#' @return TRUE if the file is valid, FALSE if not
#' @author Richel J.C. Bilderbeek
#' @seealso Use \code{\link{are_beast2_input_lines}} to check the lines
#' @export
is_beast2_input_file <- function(
filename,
show_warnings = FALSE,
verbose = FALSE,
beast2_jar_path = get_default_beast2_jar_path()
) {
Expand Down Expand Up @@ -37,14 +39,28 @@ is_beast2_input_file <- function(
# An error code of 0 denotes that the file was valid
status_code <- system(cmd, ignore.stderr = TRUE, ignore.stdout = TRUE)

# Valid BEAST2 input files will result in an output with 'Done!' at the
# last line
output <- system(cmd, intern = TRUE, ignore.stderr = TRUE)

cmds <- unlist(strsplit(x = cmd, split = " "))
output <- system2(
cmds[1],
args = cmds[2:length(cmds)],
stdout = TRUE,
stderr = TRUE
)
if (verbose) {
print(output)
}

if (show_warnings == TRUE &&
sum(grepl(x = output, pattern = "WARNING: "))) {
warning(output[grepl(x = output, pattern = "WARNING: ")])
}

if (1 == 2) {
# Valid BEAST2 input files will result in an output with 'Done!' at the
# last line
output <- system(cmd, intern = TRUE, ignore.stderr = TRUE)
}

# Invalid files are not valid BEAST2 input files
# Create an if statement here,
# if there is an input file that violates this assert,
Expand Down
4 changes: 3 additions & 1 deletion man/is_beast2_input_file.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions tests/testthat/test-is_beast2_input_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,25 @@ test_that("abuse", {
)

})

test_that("detect warnings", {

testthat::expect_warning(
is_beast2_input_file(
filename = beastier:::get_beastier_path("beast2_warning.xml"),
show_warnings = TRUE
)
)
testthat::expect_silent(
is_beast2_input_file(
filename = beastier:::get_beastier_path("beast2_warning.xml"),
show_warnings = FALSE
)
)
testthat::expect_silent(
is_beast2_input_file(
beautier:::get_beautier_paths("2_4.xml"),
show_warnings = TRUE
)
)
})

0 comments on commit a0a7efe

Please sign in to comment.