From 9836b87f71ae003973ebc86f213c9dae65a5a0b2 Mon Sep 17 00:00:00 2001 From: Ron Keizer Date: Thu, 7 Mar 2024 20:51:33 -0800 Subject: [PATCH 1/8] implement infusion duration scaling --- NAMESPACE | 1 + R/apply_duration_scale.R | 54 +++++++++++++++++++++++++++++++++++++ R/new_ode_model.R | 1 + R/sim.R | 8 ++++++ inst/template/R/model.R | 7 ++++- man/apply_duration_scale.Rd | 34 +++++++++++++++++++++++ 6 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 R/apply_duration_scale.R create mode 100644 man/apply_duration_scale.Rd diff --git a/NAMESPACE b/NAMESPACE index bf35b7dc..f9230d73 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -14,6 +14,7 @@ export(advan) export(advan_create_data) export(advan_parse_output) export(advan_process_infusion_doses) +export(apply_duration_scale) export(apply_lagtime) export(calc_auc_analytic) export(calc_ss_analytic) diff --git a/R/apply_duration_scale.R b/R/apply_duration_scale.R new file mode 100644 index 00000000..42da2135 --- /dev/null +++ b/R/apply_duration_scale.R @@ -0,0 +1,54 @@ +#' Apply infusion duration scale to a regimen +#' +#' E.g. see Centanni et al. Clin Pharmacokinet 2024. An estimated scaling factor +#' for the length of the infusion was applied there in a model for vincristine. +#' This is likely most relevant for very short infusions. +#' +#' Implementation is similar to handling of `lagtime`, i.e. the regimen that is the +#' input for the simulation function is updated. +#' +#' @param regimen PKPDsim regimen +#' @param duration_scale infusion length scale. +#' @param parameters parameter list, required if parameters are specified. +#' @param cmt_mapping map of administration types to compartments, e.g. `list("oral" = 1, "infusion" = 2, "bolus" = 2)`. +#' +#' @export +#' +#' @return Original regimen with infusion lengths scaled by a factor +#' +apply_duration_scale <- function( + regimen, + duration_scale = NULL, + parameters, + cmt_mapping = NULL +) { + if(is.null(regimen$t_inf)) { + warning("`duration_scale` is only relevant for infusion regimens with an infusion length > 0.") + return(regimen) + } + if(!is.null(duration_scale)) { + if(class(duration_scale) %in% c("numeric", "integer")) { + if(length(duration_scale) == 1) { + regimen$t_inf <- regimen$t_inf * duration_scale + } else { + regimen$t_inf <- regimen$t_inf * duration_scale[regimen$cmt] + } + } + if(class(duration_scale) %in% c("character")) { + if(length(duration_scale) == 1) { + regimen$t_inf <- regimen$t_inf * parameters[[duration_scale]] + } else { + if(is.null(regimen$cmt)) { + if(!is.null(cmt_mapping)) { + regimen$cmt <- as.numeric(cmt_mapping[regimen$type]) + } else { + regimen$cmt <- rep(1, length(regimen$dose_times)) + } + } + par_tmp <- parameters + regimen$t_inf <- regimen$t_inf + as.numeric(unlist(par_tmp[duration_scale[regimen$cmt]])) + } + } + } + return(regimen) +} diff --git a/R/new_ode_model.R b/R/new_ode_model.R index 50e46fe8..2c4df7b9 100644 --- a/R/new_ode_model.R +++ b/R/new_ode_model.R @@ -371,6 +371,7 @@ new_ode_model <- function (model = NULL, "\\[COVS\\]", covs, "\\[FIXED\\]", fixed, "\\[LAGTIME\\]", lagtime, + "\\[DURATION_SCALE\\]", deparse(dose$duration_scale), "\\[USE_IOV\\]", as.character(use_iov), "\\[IOV\\]", PKPDsim::print_list(iov, FALSE), "\\[DEVELOPMENT\\]", print_list(development, FALSE), diff --git a/R/sim.R b/R/sim.R index 147b3f25..9854fbc6 100644 --- a/R/sim.R +++ b/R/sim.R @@ -148,6 +148,14 @@ sim <- function (ode = NULL, if(!is.null(lagtime)) { regimen <- apply_lagtime(regimen, lagtime, parameters, attr(ode, "cmt_mapping")) } + if(!is.null(attr(ode, "dose")$duration_scale)) { + regimen <- apply_duration_scale( + regimen, + attr(ode, "dose")$duration_scale, + parameters, + attr(ode, "cmt_mapping") + ) + } if(t_init != 0) regimen$dose_times <- regimen$dose_times + t_init p <- as.list(parameters) if(!is.null(t_obs)) { diff --git a/inst/template/R/model.R b/inst/template/R/model.R index b00ea8ae..7220675c 100644 --- a/inst/template/R/model.R +++ b/inst/template/R/model.R @@ -4,7 +4,12 @@ model <- function(mod = NULL) { attr(ret, "cpp") <- TRUE attr(ret, "size") <- [N_COMP] attr(ret, "obs") <- list("cmt" = [OBS_COMP], "scale" = "[OBS_SCALE]", "variable" = [OBS_VARIABLE]) - attr(ret, "dose") <- list("cmt" = [DOSE_COMP], "bioav" = [DOSE_BIOAV], "duplicate" = [DOSE_DUPLICATE] ) + attr(ret, "dose") <- list( + "cmt" = [DOSE_COMP], + "bioav" = [DOSE_BIOAV], + "duplicate" = [DOSE_DUPLICATE], + "duration_scale" = [DURATION_SCALE] + ) attr(ret, "code") <- "[CODE]" attr(ret, "pk_code") <- "[PK_CODE]" attr(ret, "state_init") <- [STATE_INIT] diff --git a/man/apply_duration_scale.Rd b/man/apply_duration_scale.Rd new file mode 100644 index 00000000..94b46316 --- /dev/null +++ b/man/apply_duration_scale.Rd @@ -0,0 +1,34 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/apply_duration_scale.R +\name{apply_duration_scale} +\alias{apply_duration_scale} +\title{Apply infusion duration scale to a regimen} +\usage{ +apply_duration_scale( + regimen, + duration_scale = NULL, + parameters, + cmt_mapping = NULL +) +} +\arguments{ +\item{regimen}{PKPDsim regimen} + +\item{duration_scale}{infusion length scale.} + +\item{parameters}{parameter list, required if parameters are specified.} + +\item{cmt_mapping}{map of administration types to compartments, e.g. `list("oral" = 1, "infusion" = 2, "bolus" = 2)`.} +} +\value{ +Original regimen with infusion lengths scaled by a factor +} +\description{ +E.g. see Centanni et al. Clin Pharmacokinet 2024. An estimated scaling factor +for the length of the infusion was applied there in a model for vincristine. +This is likely most relevant for very short infusions. +} +\details{ +Implementation is similar to handling of `lagtime`, i.e. the regimen that is the +input for the simulation function is updated. +} From 86f24137c1a8059c0ac0756df495a990c3067429 Mon Sep 17 00:00:00 2001 From: Ron Keizer Date: Tue, 2 Apr 2024 09:41:46 -0700 Subject: [PATCH 2/8] rm lines not needed; add test --- R/apply_duration_scale.R | 25 ++++------- man/apply_duration_scale.Rd | 16 +++---- tests/testthat/test_apply_duration_scale.R | 49 ++++++++++++++++++++++ 3 files changed, 63 insertions(+), 27 deletions(-) create mode 100644 tests/testthat/test_apply_duration_scale.R diff --git a/R/apply_duration_scale.R b/R/apply_duration_scale.R index 42da2135..e3a4d1d2 100644 --- a/R/apply_duration_scale.R +++ b/R/apply_duration_scale.R @@ -1,16 +1,16 @@ #' Apply infusion duration scale to a regimen #' -#' E.g. see Centanni et al. Clin Pharmacokinet 2024. An estimated scaling factor +#' E.g. see Centanni et al. Clin Pharmacokinet 2024. An estimated scaling factor #' for the length of the infusion was applied there in a model for vincristine. #' This is likely most relevant for very short infusions. #' -#' Implementation is similar to handling of `lagtime`, i.e. the regimen that is the +#' Implementation is similar to handling of `lagtime`, i.e. the regimen that is the #' input for the simulation function is updated. #' #' @param regimen PKPDsim regimen #' @param duration_scale infusion length scale. -#' @param parameters parameter list, required if parameters are specified. -#' @param cmt_mapping map of administration types to compartments, e.g. `list("oral" = 1, "infusion" = 2, "bolus" = 2)`. +#' @param parameters parameter list, required if the duration scale is +#' specified as a parameter. #' #' @export #' @@ -19,10 +19,9 @@ apply_duration_scale <- function( regimen, duration_scale = NULL, - parameters, - cmt_mapping = NULL + parameters = NULL ) { - if(is.null(regimen$t_inf)) { + if(is.null(regimen$t_inf) || all(regimen$t_inf == 0)) { warning("`duration_scale` is only relevant for infusion regimens with an infusion length > 0.") return(regimen) } @@ -33,22 +32,16 @@ apply_duration_scale <- function( } else { regimen$t_inf <- regimen$t_inf * duration_scale[regimen$cmt] } - } - if(class(duration_scale) %in% c("character")) { + } else if(class(duration_scale) %in% c("character")) { if(length(duration_scale) == 1) { regimen$t_inf <- regimen$t_inf * parameters[[duration_scale]] } else { - if(is.null(regimen$cmt)) { - if(!is.null(cmt_mapping)) { - regimen$cmt <- as.numeric(cmt_mapping[regimen$type]) - } else { - regimen$cmt <- rep(1, length(regimen$dose_times)) - } - } par_tmp <- parameters regimen$t_inf <- regimen$t_inf + as.numeric(unlist(par_tmp[duration_scale[regimen$cmt]])) } } + } else { + warning("Please specify `duration_scale` to apply to regimen.") } return(regimen) } diff --git a/man/apply_duration_scale.Rd b/man/apply_duration_scale.Rd index 94b46316..f3a4a821 100644 --- a/man/apply_duration_scale.Rd +++ b/man/apply_duration_scale.Rd @@ -4,31 +4,25 @@ \alias{apply_duration_scale} \title{Apply infusion duration scale to a regimen} \usage{ -apply_duration_scale( - regimen, - duration_scale = NULL, - parameters, - cmt_mapping = NULL -) +apply_duration_scale(regimen, duration_scale = NULL, parameters = NULL) } \arguments{ \item{regimen}{PKPDsim regimen} \item{duration_scale}{infusion length scale.} -\item{parameters}{parameter list, required if parameters are specified.} - -\item{cmt_mapping}{map of administration types to compartments, e.g. `list("oral" = 1, "infusion" = 2, "bolus" = 2)`.} +\item{parameters}{parameter list, required if the duration scale is +specified as a parameter.} } \value{ Original regimen with infusion lengths scaled by a factor } \description{ -E.g. see Centanni et al. Clin Pharmacokinet 2024. An estimated scaling factor +E.g. see Centanni et al. Clin Pharmacokinet 2024. An estimated scaling factor for the length of the infusion was applied there in a model for vincristine. This is likely most relevant for very short infusions. } \details{ -Implementation is similar to handling of `lagtime`, i.e. the regimen that is the +Implementation is similar to handling of `lagtime`, i.e. the regimen that is the input for the simulation function is updated. } diff --git a/tests/testthat/test_apply_duration_scale.R b/tests/testthat/test_apply_duration_scale.R new file mode 100644 index 00000000..4470b6f5 --- /dev/null +++ b/tests/testthat/test_apply_duration_scale.R @@ -0,0 +1,49 @@ +reg_oral <- new_regimen( + amt = 1000, + n = 12, + interval = 12, + type = "oral" +) +reg_iv <- new_regimen( + amt = 1000, + n = 12, + interval = 12, + type = "infusion", + t_inf = 1 +) + +## null / error checks +test_that("infusion length NULL warning", { + expect_warning( + dur0 <- apply_duration_scale( + regimen = reg_oral + ) + ) + expect_equal(dur0, reg_oral) +}) +test_that("duration scale NULL warning", { + expect_warning( + dur1 <- apply_duration_scale( + regimen = reg_iv + ) + ) + expect_equal(dur1, reg_iv) +}) + +## Check functionality +test_that("infusion length scaled", { + dur2 <- apply_duration_scale( + regimen = reg_iv, + duration_scale = 1.5 + ) + expect_equal(dur2$t_inf, rep(1.5, 12)) +}) + +test_that("infusion length scaled using parameter", { + dur3 <- apply_duration_scale( + regimen = reg_iv, + duration_scale = "SCALE", + parameters = list(CL = 5, V = 50, SCALE = 1.6) + ) + expect_equal(dur3$t_inf, rep(1.6, 12)) +}) From 449f4e619e0a535b47c0a3fa4b545bb0e1f529d7 Mon Sep 17 00:00:00 2001 From: jasmineirx Date: Tue, 2 Apr 2024 14:24:27 -0400 Subject: [PATCH 3/8] add test for multi length scale --- tests/testthat/test_apply_duration_scale.R | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/testthat/test_apply_duration_scale.R b/tests/testthat/test_apply_duration_scale.R index 4470b6f5..17d94b3f 100644 --- a/tests/testthat/test_apply_duration_scale.R +++ b/tests/testthat/test_apply_duration_scale.R @@ -12,6 +12,15 @@ reg_iv <- new_regimen( t_inf = 1 ) +reg_combo <- new_regimen( + amt = 1000, + n = 4, + interval = 12, + type = c("drug1", "drug2", "oral", "oral"), + cmt = c(2, 3, 1, 1), + t_inf = c(1, 1, 0, 0) +) + ## null / error checks test_that("infusion length NULL warning", { expect_warning( @@ -47,3 +56,11 @@ test_that("infusion length scaled using parameter", { ) expect_equal(dur3$t_inf, rep(1.6, 12)) }) + +test_that("infusion length scaled", { + dur4 <- apply_duration_scale( + regimen = reg_combo, + duration_scale = c(1, 1.5, 2) + ) + expect_equal(dur4$t_inf, c(1.5, 2, 0)) +}) From ccb7003e8fc5ada5b3cfc3e07816a76627367cb8 Mon Sep 17 00:00:00 2001 From: Ron Keizer Date: Tue, 2 Apr 2024 14:12:36 -0700 Subject: [PATCH 4/8] misc fixes --- R/apply_duration_scale.R | 9 +++++++++ R/sim.R | 4 +--- man/apply_duration_scale.Rd | 3 +++ tests/testthat/test_apply_duration_scale.R | 13 +++++++++++-- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/R/apply_duration_scale.R b/R/apply_duration_scale.R index e3a4d1d2..7c9ab84a 100644 --- a/R/apply_duration_scale.R +++ b/R/apply_duration_scale.R @@ -11,6 +11,8 @@ #' @param duration_scale infusion length scale. #' @param parameters parameter list, required if the duration scale is #' specified as a parameter. +#' @param cmt_mapping map of administration types to compartments, e.g. +#' `list("oral" = 1, "infusion" = 2, "bolus" = 2)`. #' #' @export #' @@ -33,6 +35,13 @@ apply_duration_scale <- function( regimen$t_inf <- regimen$t_inf * duration_scale[regimen$cmt] } } else if(class(duration_scale) %in% c("character")) { + if(is.null(regimen$cmt)) { + if(!is.null(cmt_mapping)) { + regimen$cmt <- as.numeric(cmt_mapping[regimen$type]) + } else { + regimen$cmt <- rep(1, length(regimen$dose_times)) + } + } if(length(duration_scale) == 1) { regimen$t_inf <- regimen$t_inf * parameters[[duration_scale]] } else { diff --git a/R/sim.R b/R/sim.R index 9854fbc6..46e31d6b 100644 --- a/R/sim.R +++ b/R/sim.R @@ -151,9 +151,7 @@ sim <- function (ode = NULL, if(!is.null(attr(ode, "dose")$duration_scale)) { regimen <- apply_duration_scale( regimen, - attr(ode, "dose")$duration_scale, - parameters, - attr(ode, "cmt_mapping") + attr(ode, "dose")$duration_scale ) } if(t_init != 0) regimen$dose_times <- regimen$dose_times + t_init diff --git a/man/apply_duration_scale.Rd b/man/apply_duration_scale.Rd index f3a4a821..c6d5f680 100644 --- a/man/apply_duration_scale.Rd +++ b/man/apply_duration_scale.Rd @@ -13,6 +13,9 @@ apply_duration_scale(regimen, duration_scale = NULL, parameters = NULL) \item{parameters}{parameter list, required if the duration scale is specified as a parameter.} + +\item{cmt_mapping}{map of administration types to compartments, e.g. +`list("oral" = 1, "infusion" = 2, "bolus" = 2)`.} } \value{ Original regimen with infusion lengths scaled by a factor diff --git a/tests/testthat/test_apply_duration_scale.R b/tests/testthat/test_apply_duration_scale.R index 4470b6f5..0e69accf 100644 --- a/tests/testthat/test_apply_duration_scale.R +++ b/tests/testthat/test_apply_duration_scale.R @@ -9,7 +9,8 @@ reg_iv <- new_regimen( n = 12, interval = 12, type = "infusion", - t_inf = 1 + t_inf = 1, + cmt = c(1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2) ) ## null / error checks @@ -39,8 +40,16 @@ test_that("infusion length scaled", { expect_equal(dur2$t_inf, rep(1.5, 12)) }) -test_that("infusion length scaled using parameter", { +test_that("infusion length scaled using vector", { dur3 <- apply_duration_scale( + regimen = reg_iv, + duration_scale = c(1.5, 1.0) # scale oral "infusions", but not "iv" + ) + expect_equal(dur3$t_inf, rep(c(1.5, 1.0), 6)) +}) + +test_that("infusion length scaled using parameter", { + dur4 <- apply_duration_scale( regimen = reg_iv, duration_scale = "SCALE", parameters = list(CL = 5, V = 50, SCALE = 1.6) From 620815a701cea163bf458a85863839e37e1565b3 Mon Sep 17 00:00:00 2001 From: Ron Keizer Date: Tue, 2 Apr 2024 15:26:15 -0700 Subject: [PATCH 5/8] clean up --- R/apply_duration_scale.R | 3 ++- R/sim.R | 4 +++- man/apply_duration_scale.Rd | 7 ++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/R/apply_duration_scale.R b/R/apply_duration_scale.R index 7c9ab84a..7ef97714 100644 --- a/R/apply_duration_scale.R +++ b/R/apply_duration_scale.R @@ -21,7 +21,8 @@ apply_duration_scale <- function( regimen, duration_scale = NULL, - parameters = NULL + parameters = NULL, + cmt_mapping = NULL ) { if(is.null(regimen$t_inf) || all(regimen$t_inf == 0)) { warning("`duration_scale` is only relevant for infusion regimens with an infusion length > 0.") diff --git a/R/sim.R b/R/sim.R index 46e31d6b..9854fbc6 100644 --- a/R/sim.R +++ b/R/sim.R @@ -151,7 +151,9 @@ sim <- function (ode = NULL, if(!is.null(attr(ode, "dose")$duration_scale)) { regimen <- apply_duration_scale( regimen, - attr(ode, "dose")$duration_scale + attr(ode, "dose")$duration_scale, + parameters, + attr(ode, "cmt_mapping") ) } if(t_init != 0) regimen$dose_times <- regimen$dose_times + t_init diff --git a/man/apply_duration_scale.Rd b/man/apply_duration_scale.Rd index c6d5f680..05e4e46d 100644 --- a/man/apply_duration_scale.Rd +++ b/man/apply_duration_scale.Rd @@ -4,7 +4,12 @@ \alias{apply_duration_scale} \title{Apply infusion duration scale to a regimen} \usage{ -apply_duration_scale(regimen, duration_scale = NULL, parameters = NULL) +apply_duration_scale( + regimen, + duration_scale = NULL, + parameters = NULL, + cmt_mapping = NULL +) } \arguments{ \item{regimen}{PKPDsim regimen} From 5069aca7962f4d0dc7f4d0e0e00ae30a96b25212 Mon Sep 17 00:00:00 2001 From: jasmineirx Date: Wed, 3 Apr 2024 13:16:12 -0400 Subject: [PATCH 6/8] add tests, plus to multiplication --- R/apply_duration_scale.R | 2 +- tests/testthat/test_apply_duration_scale.R | 35 ++++++++++++++++++++-- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/R/apply_duration_scale.R b/R/apply_duration_scale.R index 7ef97714..1f67db36 100644 --- a/R/apply_duration_scale.R +++ b/R/apply_duration_scale.R @@ -47,7 +47,7 @@ apply_duration_scale <- function( regimen$t_inf <- regimen$t_inf * parameters[[duration_scale]] } else { par_tmp <- parameters - regimen$t_inf <- regimen$t_inf + as.numeric(unlist(par_tmp[duration_scale[regimen$cmt]])) + regimen$t_inf <- regimen$t_inf * as.numeric(unlist(par_tmp[duration_scale[regimen$cmt]])) } } } else { diff --git a/tests/testthat/test_apply_duration_scale.R b/tests/testthat/test_apply_duration_scale.R index 7beb866b..36c50d84 100644 --- a/tests/testthat/test_apply_duration_scale.R +++ b/tests/testthat/test_apply_duration_scale.R @@ -63,13 +63,42 @@ test_that("infusion length scaled using parameter", { duration_scale = "SCALE", parameters = list(CL = 5, V = 50, SCALE = 1.6) ) - expect_equal(dur3$t_inf, rep(1.6, 12)) + expect_equal(dur4$t_inf, rep(1.6, 12)) }) -test_that("infusion length scaled", { +test_that("infusion length scaled, multiple cmts", { dur4 <- apply_duration_scale( regimen = reg_combo, duration_scale = c(1, 1.5, 2) ) - expect_equal(dur4$t_inf, c(1.5, 2, 0)) + expect_equal(dur4$t_inf, c(1.5, 2, 0, 0)) +}) + +test_that("infusion length scaled, multiple cmts, no cmt", { + reg_combo$cmt <- NULL + dur5 <- apply_duration_scale( + regimen = reg_combo, + duration_scale = "SCALE", + parameters = list(CL = 5, V = 50, SCALE = 1.6), + cmt_mapping = c("drug1" = 2, "drug2" = 3, "oral" = 1) + ) + dur6 <- apply_duration_scale( + regimen = reg_combo, + duration_scale = c("SCALE1", "SCALE2", "SCALE3"), + parameters = list(CL = 5, V = 50, SCALE1 = 1.6, SCALE2 = 1.7, SCALE3 = 1.8), + cmt_mapping = c("drug1" = 2, "drug2" = 3, "oral" = 1) + ) + expect_equal(dur5$t_inf, c(1.6, 1.6, 0, 0)) + expect_equal(dur6$t_inf, c(1.7, 1.8, 0, 0)) +}) + +test_that("infusion length scaled, no cmt, no cmt_mapping", { + reg_combo$cmt <- NULL + dur7 <- apply_duration_scale( + regimen = reg_combo, + duration_scale = c("SCALE1", "SCALE2", "SCALE3"), + parameters = list(CL = 5, V = 50, SCALE1 = 1.6, SCALE2 = 1.7, SCALE3 = 1.8), + cmt_mapping = NULL + ) + expect_equal(dur7$t_inf, c(1.6, 1.6, 0, 0)) }) From 95a5cb0c712b493fd77e170390b72c86eabbb314 Mon Sep 17 00:00:00 2001 From: Ron Keizer Date: Wed, 3 Apr 2024 10:20:40 -0700 Subject: [PATCH 7/8] fix test; clean up unrelated warnings in other test --- tests/testthat/test_apply_duration_scale.R | 4 ++-- tests/testthat/test_timevar_cov.R | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test_apply_duration_scale.R b/tests/testthat/test_apply_duration_scale.R index 7beb866b..f1d00010 100644 --- a/tests/testthat/test_apply_duration_scale.R +++ b/tests/testthat/test_apply_duration_scale.R @@ -63,7 +63,7 @@ test_that("infusion length scaled using parameter", { duration_scale = "SCALE", parameters = list(CL = 5, V = 50, SCALE = 1.6) ) - expect_equal(dur3$t_inf, rep(1.6, 12)) + expect_equal(dur4$t_inf, rep(1.6, 12)) }) test_that("infusion length scaled", { @@ -71,5 +71,5 @@ test_that("infusion length scaled", { regimen = reg_combo, duration_scale = c(1, 1.5, 2) ) - expect_equal(dur4$t_inf, c(1.5, 2, 0)) + expect_equal(dur4$t_inf, c(1.5, 2, 0, 0)) }) diff --git a/tests/testthat/test_timevar_cov.R b/tests/testthat/test_timevar_cov.R index 7e91ae32..60866dbc 100644 --- a/tests/testthat/test_timevar_cov.R +++ b/tests/testthat/test_timevar_cov.R @@ -16,7 +16,7 @@ mod <- new_ode_model( pk_code = "CLi = CL + CRCL", obs = list(cmt = 2, scale = "V"), covariates = list(CRCL = new_covariate(5)), declare_variables = "CLi", - cpp = TRUE + cpp = FALSE ) test_that("timevarying covariates handled", { @@ -103,7 +103,7 @@ test_that("timevarying covariates are interpolated and affect PK", { ## Check interpolated covariates actually affect simulated conc expect_equal( round(sim2_inter$y, 3)[1:10], - c(0, 0.32, 0.611, 0.788, 1.205, 1.531, 1.708, 2.098, 2.379, 2.503), + c(0, 0.32, 0.611, 0.788, 1.205, 1.531, 1.708, 2.098, 2.379, 2.503) ) expect_equal( round(sim2_locf$y, 3)[1:10], From e1cdc8449fae749f4ce1f0e0a4533c106be6c79d Mon Sep 17 00:00:00 2001 From: jasmineirx Date: Wed, 3 Apr 2024 13:22:13 -0400 Subject: [PATCH 8/8] minor cleanup --- R/apply_duration_scale.R | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/R/apply_duration_scale.R b/R/apply_duration_scale.R index 1f67db36..8971b5cb 100644 --- a/R/apply_duration_scale.R +++ b/R/apply_duration_scale.R @@ -46,8 +46,7 @@ apply_duration_scale <- function( if(length(duration_scale) == 1) { regimen$t_inf <- regimen$t_inf * parameters[[duration_scale]] } else { - par_tmp <- parameters - regimen$t_inf <- regimen$t_inf * as.numeric(unlist(par_tmp[duration_scale[regimen$cmt]])) + regimen$t_inf <- regimen$t_inf * as.numeric(unlist(parameters[duration_scale[regimen$cmt]])) } } } else {