From a0a7efed1e683644dae2f88cffbc531c3b7aa8a3 Mon Sep 17 00:00:00 2001 From: richelbilderbeek Date: Wed, 14 Mar 2018 23:22:06 +0100 Subject: [PATCH] EOD --- R/install_beast2.R | 2 +- R/is_beast2_input_file.R | 24 ++++++++++++++++++---- man/is_beast2_input_file.Rd | 4 +++- tests/testthat/test-is_beast2_input_file.R | 22 ++++++++++++++++++++ 4 files changed, 46 insertions(+), 6 deletions(-) diff --git a/R/install_beast2.R b/R/install_beast2.R index 1c7662a..209a69c 100644 --- a/R/install_beast2.R +++ b/R/install_beast2.R @@ -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/", diff --git a/R/is_beast2_input_file.R b/R/is_beast2_input_file.R index 2439ff1..8ee0520 100644 --- a/R/is_beast2_input_file.R +++ b/R/is_beast2_input_file.R @@ -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() ) { @@ -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, diff --git a/man/is_beast2_input_file.Rd b/man/is_beast2_input_file.Rd index d615be5..dc5c345 100644 --- a/man/is_beast2_input_file.Rd +++ b/man/is_beast2_input_file.Rd @@ -4,12 +4,14 @@ \alias{is_beast2_input_file} \title{Is a file a valid BEAST2 input file?} \usage{ -is_beast2_input_file(filename, verbose = FALSE, +is_beast2_input_file(filename, show_warnings = FALSE, verbose = FALSE, beast2_jar_path = get_default_beast2_jar_path()) } \arguments{ \item{filename}{name of the BEAST2 XML input file} +\item{show_warnings}{if TRUE, warnings will shown} + \item{verbose}{if TRUE, additional information is displayed, that is potentially useful in debugging} diff --git a/tests/testthat/test-is_beast2_input_file.R b/tests/testthat/test-is_beast2_input_file.R index 0dd226b..ad56056 100644 --- a/tests/testthat/test-is_beast2_input_file.R +++ b/tests/testthat/test-is_beast2_input_file.R @@ -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 + ) + ) +})