-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More unit testing, updates to calc_* functions (#67)
* Fix 'simulate_exposure' to always return a matrix * Minor document changes * Updated 'calc_internal_dose' * typo * Updated 'calc_invitro_concentration' * Added '.check_types' function * Renamed 'tp_b_mult' to 'max_mult' * Added renv ignores * Updated 'calc_concentration_response'
- Loading branch information
1 parent
a460362
commit c2086cc
Showing
29 changed files
with
460 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
^renv$ | ||
^renv\.lock$ | ||
^\.Rprofile$ | ||
^GeoTox\.Rproj$ | ||
^\.Rproj\.user$ | ||
^LICENSE\.md$ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,54 @@ | ||
#' Calculate \emph{in vitro} concentration | ||
#' | ||
#' @description | ||
#' TODO A short description... | ||
#' Estimate the \emph{in vitro} equivalent plasma concentration given internal | ||
#' chemical dose and steady-state plasma concentration. | ||
#' | ||
#' @param D_int internal chemical dose in \eqn{\frac{mg}{kg}} | ||
#' @param C_ss steady-state plasma concentration in \eqn{\frac{\mu M}{mg / kg}} | ||
#' | ||
#' @details | ||
#' TODO Additional details... | ||
#' \deqn{C_{plasma} = C_{ss} \,\times\, D_{int}} | ||
#' Input `D_int` must be a matrix or list of matrices. Input `C_ss` must be a | ||
#' numeric atomic vector or matrix, or a list of those types. | ||
#' | ||
#' The \emph{in vitro} equivalent plasma concentration is calculated as: | ||
#' \deqn{C_{plasma} = C_{ss} \times D_{int}} | ||
#' | ||
#' @return list of matrices containing concentrations in \eqn{\mu M} | ||
#' | ||
#' @examples | ||
#' # Single population | ||
#' D_int <- matrix(1:15, ncol = 3) | ||
#' C_ss <- 1:5 | ||
#' calc_invitro_concentration(D_int, C_ss) | ||
#' | ||
#' # Multiple populations | ||
#' D_int <- list( | ||
#' "a" = matrix(1:15 / 10, ncol = 3), | ||
#' "b" = matrix(1:8, ncol = 2) | ||
#' ) | ||
#' C_ss <- list(1:5, 1:4 / 2) | ||
#' calc_invitro_concentration(D_int, C_ss) | ||
#' | ||
#' @return \emph{in vitro} equivalent plasma concentration in \eqn{\mu M} | ||
#' @export | ||
calc_invitro_concentration <- function(D_int, C_ss = NULL) { | ||
|
||
D_int <- .check_types(D_int, | ||
"matrix", | ||
"`D_int` must be a matrix or a list of matrices.") | ||
|
||
if (is.null(C_ss)) { | ||
# TODO add real-time computation of Css values | ||
stop("real-time computation of C_ss values has not been implemented") | ||
} | ||
|
||
C_ss <- .check_types(C_ss, | ||
c("matrix", "numeric", "integer"), | ||
paste("`C_ss` must be a matrix or numeric atomic", | ||
"vector, or a list of those types.")) | ||
|
||
# TODO the current C_ss data passed into this for step 01-Sensitivity.R | ||
# doesn't match the ages that were simulated? | ||
|
||
if ("matrix" %in% class(D_int)) { | ||
.calc_invitro_concentration(D_int, C_ss) | ||
} else { | ||
mapply(.calc_invitro_concentration, D_int, C_ss, SIMPLIFY = FALSE) | ||
} | ||
mapply(.calc_invitro_concentration, D_int, C_ss, SIMPLIFY = FALSE) | ||
} | ||
|
||
.calc_invitro_concentration <- function(D_int, C_ss) { | ||
as.matrix(D_int * C_ss) | ||
D_int * C_ss | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#' Check types | ||
#' | ||
#' @param x object to check | ||
#' @param types allowed types | ||
#' @param msg error message | ||
#' | ||
#' @keywords internal | ||
#' | ||
#' @return list version of input | ||
.check_types <- function(x, types, msg = "Incorrect type") { | ||
err <- FALSE | ||
if (inherits(x, types)) { | ||
x <- list(x) | ||
} else if (inherits(x, "list")) { | ||
if (!all(sapply(x, inherits, types))) { | ||
err <- TRUE | ||
} | ||
} else { | ||
err <- TRUE | ||
} | ||
if (err) stop(msg, call. = FALSE) | ||
x | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.