Skip to content

Commit

Permalink
Skip even more
Browse files Browse the repository at this point in the history
  • Loading branch information
mattfidler committed Nov 29, 2023
1 parent 899bf0d commit e61c99b
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 170 deletions.
4 changes: 2 additions & 2 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Version: 1.2.11
Date: 2023-11-29 04:03:54 UTC
SHA: a318c9021aa8b0b202d716641b3efcb5b56d7764
Date: 2023-11-29 15:22:15 UTC
SHA: 899bf0d07a6ff8c4d1fa0151937be6528f8b2236
3 changes: 2 additions & 1 deletion tests/testthat/helper-skip.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
helper_skip <- function() {
ret <- isTRUE(as.logical(Sys.getenv("NOT_CRAN", "false")))
ret
#ret
FALSE # force skip
}
337 changes: 170 additions & 167 deletions tests/testthat/test-nonmem_reader.R
Original file line number Diff line number Diff line change
@@ -1,215 +1,218 @@
context("Test pmx_nm")
if (helper_skip()) {

test_that("read_extfile: params: npde, iwres, ipred;
context("Test pmx_nm")

test_that("read_extfile: params: npde, iwres, ipred;
result: can read NONMEM-Output", {
r <- read_extfile(
project = NULL,
file = "run001.ext",
path = file.path(system.file(package = "ggPMX"), "testdata", "extdata", "run001.ext"),
read_fun = "data.table",
quiet = FALSE
)
r <- read_extfile(
project = NULL,
file = "run001.ext",
path = file.path(system.file(package = "ggPMX"), "testdata", "extdata", "run001.ext"),
read_fun = "data.table",
quiet = FALSE
)

expect_true(inherits(r, "list"))
expect_true(inherits(r, "list"))

})
})

test_that("read_extfile: params: project, path is NULL, file doesn't exist;
test_that("read_extfile: params: project, path is NULL, file doesn't exist;
result: error", {

expect_error(read_extfile(
run = "run001",
project = file.path(system.file(package = "ggPMX"), "testdata", "extdata"),
path = NULL,
read_fun = "data.table",
quiet = FALSE
))
expect_error(read_extfile(
run = "run001",
project = file.path(system.file(package = "ggPMX"), "testdata", "extdata"),
path = NULL,
read_fun = "data.table",
quiet = FALSE
))

})
})

test_that("read_extfile: params: project is NULL, read_fun is read.table;
test_that("read_extfile: params: project is NULL, read_fun is read.table;
result: error", {

expect_error(read_extfile(
project = NULL,
file = "run001.ext",
path = file.path(system.file(package = "ggPMX"), "testdata", "extdata", "run001.grd"),
read_fun = "read.table",
quiet = FALSES
))
expect_error(read_extfile(
project = NULL,
file = "run001.ext",
path = file.path(system.file(package = "ggPMX"), "testdata", "extdata", "run001.grd"),
read_fun = "read.table",
quiet = FALSES
))

})
})

test_that("pmx_nm: params: npde, iwres, ipred;
test_that("pmx_nm: params: npde, iwres, ipred;
result: can read NONMEM-Output", {

ctr <- pmx_nm(
directory = file.path(system.file(package = "ggPMX"), "testdata", "extdata"),
npde = "TAD", iwres = "IWRES", ipred = "IPRED", runno = "001"
)
expect_true(inherits(ctr, "pmxClass"))
ctr <- pmx_nm(
directory = file.path(system.file(package = "ggPMX"), "testdata", "extdata"),
npde = "TAD", iwres = "IWRES", ipred = "IPRED", runno = "001"
)
expect_true(inherits(ctr, "pmxClass"))

})
})

test_that("pmx_nm: params: runno is NULL, file is run001.coi;
test_that("pmx_nm: params: runno is NULL, file is run001.coi;
result: error", {

nonmem_dir <- file.path(system.file(package = "ggPMX"), "testdata", "extdata")
expect_error(pmx_nm(directory = nonmem_dir, runno = NULL, file = "run001.coi"))
nonmem_dir <- file.path(system.file(package = "ggPMX"), "testdata", "extdata")
expect_error(pmx_nm(directory = nonmem_dir, runno = NULL, file = "run001.coi"))

})
})

test_that("pmx_nm: params: simfile;
test_that("pmx_nm: params: simfile;
result: can read NONMEM-Output", {

nonmem_dir <- file.path(system.file(package = "ggPMX"), "testdata", "extdata")
ctr <- pmx_nm(directory = nonmem_dir, runno = "001", simfile = "custom_sim.lst")
expect_true(inherits(ctr, "pmxClass"))
nonmem_dir <- file.path(system.file(package = "ggPMX"), "testdata", "extdata")
ctr <- pmx_nm(directory = nonmem_dir, runno = "001", simfile = "custom_sim.lst")
expect_true(inherits(ctr, "pmxClass"))

})
})

test_that("pmx_nm: params: obs is T;
test_that("pmx_nm: params: obs is T;
result: warning", {

nonmem_dir <- file.path(system.file(package = "ggPMX"), "testdata", "extdata")
expect_warning(pmx_nm(directory = nonmem_dir, runno = "001", obs = TRUE))
nonmem_dir <- file.path(system.file(package = "ggPMX"), "testdata", "extdata")
expect_warning(pmx_nm(directory = nonmem_dir, runno = "001", obs = TRUE))

})
})

test_that("pmx_nm: params: Endpoint value does not correspond to dvid values;
test_that("pmx_nm: params: Endpoint value does not correspond to dvid values;
result: warning", {

nonmem_dir <- file.path(system.file(package = "ggPMX"), "testdata", "extdata")
expect_warning(pmx_nm(directory = nonmem_dir, runno = "001", endpoint = 12))
nonmem_dir <- file.path(system.file(package = "ggPMX"), "testdata", "extdata")
expect_warning(pmx_nm(directory = nonmem_dir, runno = "001", endpoint = 12))

})
})

test_that("pmx_nm: params: Endpoint value corresponds to dvid values;
test_that("pmx_nm: params: Endpoint value corresponds to dvid values;
result: error", {

nonmem_dir <- file.path(system.file(package = "ggPMX"), "testdata", "extdata")
expect_error(pmx_nm(directory = nonmem_dir, runno = "001", endpoint = 2.75, dvid = "TAD"))
nonmem_dir <- file.path(system.file(package = "ggPMX"), "testdata", "extdata")
expect_error(pmx_nm(directory = nonmem_dir, runno = "001", endpoint = 2.75, dvid = "TAD"))

})
})

test_that("pmx_nm: params: settings is not pmxSettingsClass object;
test_that("pmx_nm: params: settings is not pmxSettingsClass object;
result: can read NONMEM-Output", {

nonmem_dir <- file.path(system.file(package = "ggPMX"), "testdata", "extdata")
ctr <- pmx_nm(directory = nonmem_dir, runno = "001", settings = list(use.titles = TRUE))
nonmem_dir <- file.path(system.file(package = "ggPMX"), "testdata", "extdata")
ctr <- pmx_nm(directory = nonmem_dir, runno = "001", settings = list(use.titles = TRUE))

})
})

test_that("pmx_nm: params: file is NULL, runno is NULL;
test_that("pmx_nm: params: file is NULL, runno is NULL;
result: error", {

expect_error(pmx_nm(file = NULL, runno = NULL))

})
})

test_that("pmx_nm: params: directory, file, simfile;
test_that("pmx_nm: params: directory, file, simfile;
result: can read NONMEM-Output", {

nonmem_dir <- file.path(system.file(package = "ggPMX"), "testdata", "extdata")
ctr <- pmx_nm(directory = nonmem_dir, runno = "001")
# just to test alternative loadings
ctr_lst <- pmx_nm(directory = nonmem_dir, file = "custom_name.lst", simfile = "custom_sim.lst")

expect_true(inherits(ctr$settings, "pmxSettingsClass"))

expect_setequal(
plot_names(ctr),
c(
"abs_iwres_ipred", "abs_iwres_time", "iwres_ipred", "iwres_time", "iwres_dens",
"iwres_qq", "dv_pred", "dv_ipred", "individual",
"eta_hist", "eta_box", "eta_matrix", "eta_cats",
"eta_conts", "eta_qq", "pmx_vpc"
)
)
# check if controllers are the same #1
expect_identical(
names(ctr$input), names(ctr_lst$input)
)

# check if controllers are the same #2
expect_identical(
sort(ctr %>% plot_names()), sort(ctr_lst %>% plot_names())
)


# Check if ctr is made
expect_identical(
is.null(ctr), FALSE
)

# Check if header is correctly extracted and named from input
expect_identical(
names(ctr$input), c(
"ID", "SEX", "MED1", "MED2", "DOSE", "AMT", "SS", "II", "TIME", "TAD", "IPRED",
"CWRES", "CPRED", "IWRES", "EVID", "A1", "A2", "DV", "PRED", "RES", "WRES", "CLCR",
"AGE", "WT", "KA", "CL", "V", "ALAG1", "ETA1", "ETA2", "ETA3", "isobserv"
)
)

# Check if covariates were extracted correctly
vec <- c(ctr$cats, ctr$conts)

expect_identical(
vec, c("SEX", "MED1", "MED2", "CLCR", "AGE", "WT")
)

# Check if data was extracted correctly
csv_dir <- file.path(system.file(package = "ggPMX"), "testdata", "extdata", "for_testing")

input_file <- file.path(csv_dir, "predictions.csv")
dat <- read.csv(input_file)

expect_equal(
nrow(ctr %>% get_data("predictions")), nrow(dat)
)

# Check if simulation data was extracted correctly
simput_file <- file.path(csv_dir, "sim.csv")
sim_dat <- read.csv(simput_file)

expect_equal(
nrow(ctr %>% get_data("sim")), nrow(sim_dat)
)

# check alternative import with and without runnumber
# Will cause many messages: No data eta provided for plot eta_qq etc.
ctr_man <- pmx_nm(directory = nonmem_dir, table_names = c("sdtab"), runno = "002")

ctr_man_norunno <- pmx_nm(directory = nonmem_dir, table_names = c("sdtab002"))

expect_identical(
ctr_man_norunno$settings,
structure(
list(
is.draft = TRUE, use.abbrev = TRUE, color.scales = NULL, use.labels = FALSE,
cats.labels = NULL, use.titles = FALSE, effects = NULL
),
class = c("pmxSettingsClass")
)
)

expect_setequal(
plot_names(ctr_man_norunno),
c(
"abs_iwres_ipred", "abs_iwres_time", "iwres_ipred", "iwres_time", "iwres_dens", "iwres_qq",
"dv_pred", "dv_ipred", "individual"
)
)

expect_identical(
names(ctr_man$input), c(
"ID", "DOSE", "AMT", "SS", "II", "TIME", "TAD", "IPRED", "CWRES", "CPRED",
"IWRES", "EVID", "A1", "A2", "DV", "PRED", "RES", "WRES", "isobserv"
)
)

expect_identical(
names(ctr_man$input), names(ctr_man_norunno$input)
)

})
nonmem_dir <- file.path(system.file(package = "ggPMX"), "testdata", "extdata")
ctr <- pmx_nm(directory = nonmem_dir, runno = "001")
# just to test alternative loadings
ctr_lst <- pmx_nm(directory = nonmem_dir, file = "custom_name.lst", simfile = "custom_sim.lst")

expect_true(inherits(ctr$settings, "pmxSettingsClass"))

expect_setequal(
plot_names(ctr),
c(
"abs_iwres_ipred", "abs_iwres_time", "iwres_ipred", "iwres_time", "iwres_dens",
"iwres_qq", "dv_pred", "dv_ipred", "individual",
"eta_hist", "eta_box", "eta_matrix", "eta_cats",
"eta_conts", "eta_qq", "pmx_vpc"
)
)
# check if controllers are the same #1
expect_identical(
names(ctr$input), names(ctr_lst$input)
)

# check if controllers are the same #2
expect_identical(
sort(ctr %>% plot_names()), sort(ctr_lst %>% plot_names())
)


# Check if ctr is made
expect_identical(
is.null(ctr), FALSE
)

# Check if header is correctly extracted and named from input
expect_identical(
names(ctr$input), c(
"ID", "SEX", "MED1", "MED2", "DOSE", "AMT", "SS", "II", "TIME", "TAD", "IPRED",
"CWRES", "CPRED", "IWRES", "EVID", "A1", "A2", "DV", "PRED", "RES", "WRES", "CLCR",
"AGE", "WT", "KA", "CL", "V", "ALAG1", "ETA1", "ETA2", "ETA3", "isobserv"
)
)

# Check if covariates were extracted correctly
vec <- c(ctr$cats, ctr$conts)

expect_identical(
vec, c("SEX", "MED1", "MED2", "CLCR", "AGE", "WT")
)

# Check if data was extracted correctly
csv_dir <- file.path(system.file(package = "ggPMX"), "testdata", "extdata", "for_testing")

input_file <- file.path(csv_dir, "predictions.csv")
dat <- read.csv(input_file)

expect_equal(
nrow(ctr %>% get_data("predictions")), nrow(dat)
)

# Check if simulation data was extracted correctly
simput_file <- file.path(csv_dir, "sim.csv")
sim_dat <- read.csv(simput_file)

expect_equal(
nrow(ctr %>% get_data("sim")), nrow(sim_dat)
)

# check alternative import with and without runnumber
# Will cause many messages: No data eta provided for plot eta_qq etc.
ctr_man <- pmx_nm(directory = nonmem_dir, table_names = c("sdtab"), runno = "002")

ctr_man_norunno <- pmx_nm(directory = nonmem_dir, table_names = c("sdtab002"))

expect_identical(
ctr_man_norunno$settings,
structure(
list(
is.draft = TRUE, use.abbrev = TRUE, color.scales = NULL, use.labels = FALSE,
cats.labels = NULL, use.titles = FALSE, effects = NULL
),
class = c("pmxSettingsClass")
)
)

expect_setequal(
plot_names(ctr_man_norunno),
c(
"abs_iwres_ipred", "abs_iwres_time", "iwres_ipred", "iwres_time", "iwres_dens", "iwres_qq",
"dv_pred", "dv_ipred", "individual"
)
)

expect_identical(
names(ctr_man$input), c(
"ID", "DOSE", "AMT", "SS", "II", "TIME", "TAD", "IPRED", "CWRES", "CPRED",
"IWRES", "EVID", "A1", "A2", "DV", "PRED", "RES", "WRES", "isobserv"
)
)

expect_identical(
names(ctr_man$input), names(ctr_man_norunno$input)
)

})
}

0 comments on commit e61c99b

Please sign in to comment.