@@ -127,20 +127,20 @@ new_regimen <- function(
127127 if (length(reg $ type ) != length(reg $ dose_times )) {
128128 reg $ type <- rep(reg $ type [1 ], length(reg $ dose_times ))
129129 }
130- if (any(reg $ type %in% c(" infusion" , " sc" , " im" ))) {
131- if (any(reg $ t_inf == 0 )) {
132- reg $ t_inf [reg $ t_inf == 0 ] <- 1 / 60
133- reg $ rate [reg $ t_inf == 0 ] <- 60
130+ # set oral/bolus t_inf to zero, and non-oral/bolus t_inf to minimum 1 minute
131+ idx_bolus_oral <- is_bolus_or_oral(reg )
132+ if (! all(idx_bolus_oral )) {
133+ idx_infusion_0length <- reg $ t_inf == 0 & ! idx_bolus_oral
134+ if (any(idx_infusion_0length )) {
135+ reg $ t_inf [idx_infusion_0length ] <- 1 / 60
136+ reg $ rate [idx_infusion_0length ] <- 60
134137 }
135138 }
136- if (any(reg $ type == " bolus" )) {
137- reg $ t_inf [reg $ type == " bolus" ] <- 0
138- reg $ rate [reg $ type == " bolus" ] <- 0
139- }
140- if (any(grepl(" oral" , reg $ type ))) {
141- reg $ t_inf [grepl(" oral" , reg $ type )] <- 0
142- reg $ rate [grepl(" oral" , reg $ type )] <- 0
139+ if (any(is_bolus_or_oral(reg ))) {
140+ reg $ t_inf [is_bolus_or_oral(reg )] <- 0
141+ reg $ rate [is_bolus_or_oral(reg )] <- 0
143142 }
143+
144144 if (! is.null(cmt )) {
145145 if (length(cmt ) != length(reg $ dose_times )) {
146146 cmt <- rep(cmt [1 ], length(reg $ dose_times ))
@@ -160,3 +160,17 @@ new_regimen <- function(
160160 }
161161 return (reg )
162162}
163+
164+ # ' Is regimen type oral or bolus? (i.e., treat t_inf as zero)
165+ # '
166+ # ' Any regimen matching exactly the string 'bolus' or containing the string
167+ # ' 'oral' will return `TRUE`, otherwise `FALSE`. Bolus/oral regimens are
168+ # ' generally treated as having an infusion duration of zero.
169+ # '
170+ # ' @param regimen object of class "regimen"`
171+ # ' @returns Returns a logical vector of length equal to the number of doses in
172+ # ' the regimen
173+
174+ is_bolus_or_oral <- function (regimen ) {
175+ regimen $ type == " bolus" | grepl(" oral" , regimen $ type )
176+ }
0 commit comments