diff --git a/NEWS.md b/NEWS.md index ce88004f..38e833aa 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,7 @@ # xpose 0.4.17.9000 * Compatibility fix for `roxygen2` 7.3.1 * Fix bug when reading a control stream and using `$PROB` instead of `$PROBLEM` (@AndreasCalvagone, #222) +* Introduced `check_ext` argument in `xpose_data()`, `read_nm_model()`, to bypass the strict NONMEM model format check if needed. * Small documentation fixes and improvements # xpose 0.4.17 diff --git a/R/read_nm_model.R b/R/read_nm_model.R index dd432c32..f387b4e9 100755 --- a/R/read_nm_model.R +++ b/R/read_nm_model.R @@ -35,11 +35,12 @@ #' } #' #' @export -read_nm_model <- function(runno = NULL, - prefix = 'run', - ext = '.lst', - file = NULL, - dir = NULL) { +read_nm_model <- function(runno = NULL, + prefix = 'run', + ext = '.lst', + file = NULL, + dir = NULL, + check_ext = TRUE) { if (is.null(runno) && is.null(file)) { stop('Argument `runno` or `file` required.', call. = FALSE) @@ -53,8 +54,12 @@ read_nm_model <- function(runno = NULL, full_path <- file_path(dir, file) } - if (!ext %in% c('.lst', '.out', '.res', '.mod', '.ctl')) { - stop('NONMEM model file extension should be one lst, out, res, mod or ctl.', call. = FALSE) + if (check_ext & !ext %in% c('.lst', '.out', '.res', '.mod', '.ctl')) { + stop( + paste( + 'NONMEM model file extension should be one of .lst, .out, .res, .mod or .ctl. If you want to use the', + ext ,'extension anyway use `check_ext = FALSE`'), + call. = FALSE) } if (!file.exists(full_path)) { diff --git a/R/xpose_data.R b/R/xpose_data.R index 882a878e..78f71bd7 100755 --- a/R/xpose_data.R +++ b/R/xpose_data.R @@ -6,7 +6,7 @@ #' combination with \code{prefix} and \code{ext}. #' @param prefix Prefix to be used to generate model file name. Used in #' combination with \code{runno} and \code{ext}. -#' @param ext Extension to be used to generate model file name.Should be one of +#' @param ext Extension to be used to generate model file name. Should be one of #' '.lst' (default), '.out', '.res', '.mod' or '.ctl' for NONMEM. #' @param file Model file name (preferably a '.lst' file) containing the file #' extension. Alternative to \code{prefix}, \code{runno} and \code{ext} @@ -26,18 +26,22 @@ #' \code{\link{manual_nm_import}}. #' @param ignore Character vector be used to ignore the import/generation of: #' 'data', 'files', 'summary' or any combination of the three. +#' @param check_ext Logical, if \code{TRUE} will provide an error message if the +#' extension of the NONMEM input file is not one of '.lst', '.out', '.res', +#' '.mod' or '.ctl' for NONMEM. If \code {FALSE} any file extension can be +#' used. #' @param extra_files A vector of additional output file extensions to be -#' imported. Default is '.ext', '.cov', '.cor', '.phi', ".grd" for NONMEM. +#' imported. Default is '.ext', '.cov', '.cor', '.phi', '.grd' for NONMEM. #' @param quiet Logical, if \code{FALSE} messages are printed to the console. #' @param ... Additional arguments to be passed to the #' \code{\link{read_nm_tables}} functions. #' #' @section File path generation: The rules for model file names generation are -#' as follow: \itemize{ +#' as follow: \itemize{ #' \item with \code{runno}: the full path is generated as #' \code{/.} e.g. with \code{dir = 'model/pk'}, #' \code{prefix = 'run'}, \code{runno = '001'}, \code{ext = '.lst'} the -#' resulting path would be \code{model/pk/run001.lst} +#' resulting path would be \code{model/pk/run001.lst} #' \item with \code{file}: #' the full path is generated as \code{/} e.g. with \code{dir = #' 'model/pk'}, \code{file = 'run001.lst'} the resulting path would also be @@ -82,6 +86,7 @@ xpose_data <- function(runno = NULL, simtab = NULL, manual_import = NULL, ignore = NULL, + check_ext = TRUE, extra_files, quiet, ...) { @@ -111,10 +116,11 @@ xpose_data <- function(runno = NULL, } # List tables - if (ext %in% c('.lst', '.out', '.res', '.mod', '.ctl')) { + if (ext %in% c('.lst', '.out', '.res', '.mod', '.ctl') | !check_ext) { software <- 'nonmem' - model_code <- read_nm_model(file = basename(full_path), - dir = dirname(full_path)) + model_code <- read_nm_model(file = basename(full_path), + dir = dirname(full_path), + check_ext = check_ext) if (is.null(manual_import)) { tbl_names <- list_nm_tables(model_code) @@ -123,7 +129,9 @@ xpose_data <- function(runno = NULL, dir = dirname(full_path), tab_list = manual_import) } } else { - stop('Model file currently not supported by xpose.', call. = FALSE) + stop(paste( + 'Model file currently not supported by xpose. If you want to use the', + ext ,'extension anyway use `check_ext = FALSE`'), call. = FALSE) } # Import estimation tables diff --git a/tests/testthat/test-read_nm_model.R b/tests/testthat/test-read_nm_model.R index 7ec45f22..3fbeac06 100755 --- a/tests/testthat/test-read_nm_model.R +++ b/tests/testthat/test-read_nm_model.R @@ -8,7 +8,7 @@ test_that('error is returned when missing file and runno arguments', { }) test_that('error is returned when extension is unrecognized', { - expect_error(read_nm_model(file = 'run001.exe', dir = 'data'), regexp = 'NONMEM model file extension should be one lst, out, res, mod or ctl.') + expect_error(read_nm_model(file = 'run001.exe', dir = 'data'), regexp = 'NONMEM model file extension should be one of .lst, .out, .res, .mod or .ctl. If you want to use the .exe extension anyway use `check_ext = FALSE`') }) test_that('error is returned when file does not exist', {