Skip to content
Open
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: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ S3method(model.frame,PKNCAdose)
S3method(mutate,PKNCAconc)
S3method(mutate,PKNCAdose)
S3method(mutate,PKNCAresults)
S3method(pknca_unit_conversion,PKNCAresults)
S3method(pknca_unit_conversion,data.frame)
S3method(print,PKNCAconc)
S3method(print,PKNCAdata)
S3method(print,PKNCAdose)
Expand Down Expand Up @@ -214,6 +216,7 @@ export(pk.nca.interval)
export(pk.tss)
export(pk.tss.monoexponential)
export(pk.tss.stepwise.linear)
export(pknca_unit_conversion)
export(pknca_units_table)
export(right_join)
export(roundString)
Expand Down
4 changes: 2 additions & 2 deletions R/class-PKNCAdata.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ PKNCAdata.PKNCAdose <- function(data.conc, data.dose, ...) {
PKNCAdata.default <- function(data.conc, data.dose, ...,
formula.conc, formula.dose,
impute = NA_character_,
intervals, units, options=list()) {
intervals, units = NULL, options=list()) {
if (length(list(...))) {
stop("Unknown argument provided to PKNCAdata. All arguments other than `data.conc` and `data.dose` must be named.")
}
Expand Down Expand Up @@ -169,7 +169,7 @@ PKNCAdata.default <- function(data.conc, data.dose, ...,
units_interval_end <- inherits(ret$intervals$end, "units")

# Insert the unit conversion table
if (missing(units)) {
if (is.null(units)) {
# What unit types are recognized?
possible_units <-
setdiff(
Expand Down
31 changes: 29 additions & 2 deletions R/unit-support.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,15 @@ pknca_units_table <- function(concu, doseu, amountu, timeu,
# Use the original conversions argument over `conversions_pref`
mask_pref <- conversions_pref$PPORRESU %in% conversions$PPORRESU[idx]
if (!any(mask_pref)) {
stop("Cannot find PPORRESU match between conversions and preferred unit conversions. Check PPORRESU values in 'conversions' argument.")
stop(
paste(
sprintf(
"Cannot find PPORRESU match between conversions and preferred unit conversions (%s).",
paste0('"', unique(conversions_pref$PPORRESU[!mask_pref]), '"', collapse = ", ")
),
"Check PPORRESU values in 'conversions' argument."
)
)
}
conversions_pref$PPSTRESU[mask_pref] <- conversions$PPSTRESU[idx]
conversions_pref$conversion_factor[mask_pref] <- conversions$conversion_factor[idx]
Expand Down Expand Up @@ -391,7 +399,26 @@ pknca_units_add_paren <- function(unit) {
#' but not all parameters?
#' @returns The result table with units converted
#' @keywords Internal
pknca_unit_conversion <- function(result, units, allow_partial_missing_units = FALSE) {
#' @export
pknca_unit_conversion <- function(result, units = NULL, allow_partial_missing_units = FALSE) {
UseMethod("pknca_unit_conversion")
}

#' @describeIn pknca_unit_conversion Convert PKNCA units for a data.frame
#' @export
pknca_unit_conversion.PKNCAresults <- function(result, units = NULL, allow_partial_missing_units = FALSE) {
result$result <-
pknca_unit_conversion(
result$result,
units = units,
allow_partial_missing_units = allow_partial_missing_units
)
result
}

#' @describeIn pknca_unit_conversion Convert PKNCA units for a data.frame
#' @export
pknca_unit_conversion.data.frame <- function(result, units = NULL, allow_partial_missing_units = FALSE) {
ret <- result
if (!is.null(units)) {
ret <-
Expand Down
2 changes: 1 addition & 1 deletion man/PKNCAdata.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 26 additions & 1 deletion man/pknca_unit_conversion.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading