Skip to content

Commit

Permalink
error out if any unsupported fortran logical operators are found
Browse files Browse the repository at this point in the history
  • Loading branch information
barrettk committed Aug 14, 2024
1 parent aa5c54b commit 2531941
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
12 changes: 12 additions & 0 deletions R/filter-nm-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ get_data_filter_exprs <- function(.mod){
#' @keywords internal
#' @seealso [invert_operator()], [translate_nm_expr()]
translate_nm_operator <- function(expr) {
# Check for unsupported operators
bad_ops <- c(".OR.",".AND", ".NOT.")
bad_ops_pat <- paste(bad_ops, collapse = "|")
if(any(grepl(bad_ops_pat, expr))){
cli::cli_abort(
c(
"The following logical operators are not supported {.var {bad_ops}}",
"i" = "See NONMEM documentation for more details"
)
)
}

# Equal
expr <- gsub(".EQ.", "==", expr, fixed = TRUE)
expr <- gsub(".EQN.", "==", expr, fixed = TRUE)
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test-filter-nm-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ test_that("translate_nm_expr() translates NONMEM filter expressions", {
translate_nm_expr("@", data_cols = data_cols),
paste0("!grepl('^\\\\s*[A-Za-z@]', ", data_cols[1], ")")
)

# Error out for unsupported logical operators
test_exprs_bad <- c(test_exprs, "GEN=1 .AND. AGE > 60")
expect_error(
translate_nm_expr(test_exprs_bad, type = 'accept'),
"The following logical operators are not supported"
)
})

test_that("filter_nm_data() filters input data using IGNORE/ACCEPT options", {
Expand Down

0 comments on commit 2531941

Please sign in to comment.