Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase code coverage #357

Merged
merged 6 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions R/aucint.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ pk.calc.aucint <- function(conc, time,
tlast <- pk.calc.tlast(conc=data$conc, time=data$time)
clast_obs <- pk.calc.clast.obs(conc=data$conc, time=data$time)
if (is.na(clast)) {
# All concentrations are NA
return(structure(NA_real_, exclude = "clast is NA"))
stop("Please report a bug. clast is NA") # nocov
} else if (clast != clast_obs & interval[2] > tlast) {
# If using clast.pred, we need to doubly calculate at tlast.
conc_clast <- clast
Expand Down
4 changes: 2 additions & 2 deletions R/class-PKNCAdata.R
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,14 @@ PKNCAdata.default <- function(data.conc, data.dose, ...,

unit_args <- conc_units_values
for (nm in names(conc_units_cols)) {
unit_args[[nm]] <- unique(na.omit(ret$conc$data[[conc_units_cols[[nm]]]]))
unit_args[[nm]] <- unique(stats::na.omit(ret$conc$data[[conc_units_cols[[nm]]]]))
}

if (!identical(ret$dose, NA)) {
unit_args <- append(unit_args, ret$dose$units)
dose_units_cols <- ret$dose$columns[names(ret$dose$columns) %in% possible_units]
for (nm in names(dose_units_cols)) {
unit_args[[nm]] <- unique(na.omit(ret$dose$data[[dose_units_cols[[nm]]]]))
unit_args[[nm]] <- unique(stats::na.omit(ret$dose$data[[dose_units_cols[[nm]]]]))
}
}
# If there are any units to set, set them here
Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test-001-add.interval.col.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ test_that("add.interval.col", {
regexp="desc must be a character string",
info="interval column description must be a character scalar"
)
expect_error(
add.interval.col(name="a", FUN=NA, depends = 1, unit_type="conc", pretty_name="a", datatype="interval", desc=1),
regexp="'depends' must be NULL or a character vector",
info="depends column must be a NULL or a character string"
)

expect_error(
add.interval.col(name="a", FUN="this function does not exist", unit_type="conc", pretty_name="foo", datatype="interval", desc="test addition"),
Expand Down
19 changes: 19 additions & 0 deletions tests/testthat/test-assertions.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,25 @@ test_that("assert_PKNCAdata", {
)
})

test_that("element_find", {
values5<-c(TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE)
values10<-c(TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE)
expect_equal(
element_find(values5),
element_find(values10)
)

expect_equal(
element_find(values5),
"Elements 1, 2, 3, 4, 5"
)

expect_equal(
element_find(values10),
"Elements 1, 2, 3, 4, 5"
)
})

test_that("assert_unit_col", {
d <- data.frame(A = 1, B = "C")
expect_equal(
Expand Down
22 changes: 22 additions & 0 deletions tests/testthat/test-class-PKNCAdata.R
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ test_that("print.PKNCAdata", {
intervals=data.frame(start=0, end=24, aucinf.obs=TRUE),
options=list(min.hl.r.squared=0.95))
obj.data.dose <- PKNCAdata(obj.conc, data.dose=obj.dose)
obj.data.units <- PKNCAdata(obj.conc,
intervals=data.frame(start=0, end=24, aucinf.obs=TRUE))
obj.data.units$units <- "mg"

expect_output(print.PKNCAdata(obj.data.nodose),
regexp="Formula for concentration:
Expand Down Expand Up @@ -217,6 +220,25 @@ Options changed from default are:
$min.hl.r.squared
[1] 0.95",
info="Generic print.PKNCAdata works with no dosing and with options changed")
expect_output(print.PKNCAdata(obj.data.units),
regexp="Formula for concentration:
conc ~ time | treatment + ID
With 2 subjects defined in the 'ID' column.
Nominal time column is not specified.

First 6 rows of concentration data:
treatment ID time conc exclude
Trt 1 1 0 0.0000000 <NA>
Trt 1 1 1 0.7052248 <NA>
Trt 1 1 2 0.7144320 <NA>
Trt 1 1 3 0.8596094 <NA>
Trt 1 1 4 0.9998126 <NA>
Trt 1 1 5 0.7651474 <NA>
No dosing information.
With units
With 1 rows of interval specifications.
No options are set differently than default.",
info="Generic print.PKNCAdata works with no dosing")
})

test_that("summary.PKNCAdata", {
Expand Down
Loading