Skip to content

Commit

Permalink
intervals argument to PKNCAdata may now be a tibble (fix #72)
Browse files Browse the repository at this point in the history
  • Loading branch information
billdenney committed Sep 26, 2018
1 parent 29f50bf commit 8d6da65
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: PKNCA
Type: Package
Title: Perform Pharmacokinetic Non-Compartmental Analysis
Version: 0.8.5.9007
Version: 0.8.5.9008
Authors@R: c(
person("Bill", "Denney", email="wdenney@humanpredictions.com", role=c("aut", "cre"), comment=c(ORCID="0000-0002-5759-428X")),
person("Clare", "Buckeridge", email="clare.buckeridge@pfizer.com", role="aut"),
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ the dosing including dose amount and route.
`PKNCAresults` objects.
* `PKNCAdata()` is more restrictive on unknown arguments issuing an error
when unknonwn arguments are present.
* `intervals` argument to `PKNCAdata()` may now be a tibble (fixes #72).

# PKNCA 0.8.5

Expand Down
16 changes: 10 additions & 6 deletions R/pk.calc.all.R
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ pk.nca.intervals <- function(conc.dose, intervals, options) {
duration.dose.group=dose_data_group[[col.duration.dose]],
route.group=dose_data_group[[col.route]],
# Generic data
interval=all.intervals[i,],
interval=all.intervals[i, , drop=FALSE],
options=options)
if (!is.null(col.include_half.life)) {
args$include_half.life <- conc_data_interval[[col.include_half.life]]
Expand Down Expand Up @@ -305,8 +305,9 @@ pk.nca.interval <- function(conc, time, volume, duration.conc,
dose.group=NULL, time.dose.group=NULL, duration.dose.group=NULL, route.group=NULL,
include_half.life=NULL, exclude_half.life=NULL,
interval, options=list()) {
if (!is.data.frame(interval))
if (!is.data.frame(interval)) {
stop("interval must be a data.frame")
}
if (nrow(interval) != 1)
stop("interval must be a one-row data.frame")
## Prepare the return value using SDTM names
Expand All @@ -325,13 +326,16 @@ pk.nca.interval <- function(conc, time, volume, duration.conc,
}
## Make sure that we calculate all of the dependencies. Do this in
## reverse order for dependencies of dependencies.
for (n in rev(names(all.intervals)))
if (interval[1,n])
for (deps in all.intervals[[n]]$depends)
for (n in rev(names(all.intervals))) {
if (interval[[1,n]]) {
for (deps in all.intervals[[n]]$depends) {
interval[1,deps] <- TRUE
}
}
}
## Do the calculations
for (n in names(all.intervals))
if (interval[1,n] & !is.na(all.intervals[[n]]$FUN)) {
if (interval[[1,n]] & !is.na(all.intervals[[n]]$FUN)) {
call.args <- list()
## Prepare to call the function by setting up its arguments.
## Ignore the "..." argument if it exists.
Expand Down
18 changes: 17 additions & 1 deletion tests/testthat/test-class-PKNCAdata.R
Original file line number Diff line number Diff line change
Expand Up @@ -321,4 +321,20 @@ test_that("Ensure that unexpected arguments to PKNCAdata give an error (related
PKNCAdose(tmp.dose, formula=dose~time|treatment+ID)
expect_error(mydata <- PKNCAdata(obj.conc, obj.dose, 1),
regexp="Unknown argument")
})
})

test_that("intervals may be a tibble", {
tmp.conc <- generate.conc(nsub=2, ntreat=1, time.points=0:24)
tmp.dose <- generate.dose(tmp.conc)
obj.conc <-
PKNCAconc(tmp.conc, formula=conc~time|treatment+ID)
obj.dose <-
PKNCAdose(tmp.dose, formula=dose~time|treatment+ID)
intervals <- data.frame(start=0, end=24, aucinf.obs=TRUE)
mydata_tibble <- PKNCAdata(obj.conc, obj.dose, intervals=as_data_frame(intervals))
mydata <- PKNCAdata(obj.conc, obj.dose, intervals=intervals)
expect_equal(
as.data.frame(pk.nca(mydata_tibble)),
as.data.frame(pk.nca(mydata))
)
})

0 comments on commit 8d6da65

Please sign in to comment.