-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Variable population size update (#78)
* Variable pop size for simulate functions * Update GeoTox.print * Message format consistency * Ran devtools::document() * Added set_population function * Updated paper doi * Increment version number to 0.2.0.9001 * Updated NEWS * Added set_population to _pkgdown.yml * Updated documentation * Fix for devtools::check() note
- Loading branch information
1 parent
f2b0809
commit c1a6017
Showing
26 changed files
with
567 additions
and
155 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
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,5 +1,10 @@ | ||
# GeoTox (development version) | ||
|
||
* Added set_population() function. | ||
|
||
* The simulate\_\* functions can now handle population sizes that vary | ||
across regions. | ||
|
||
# GeoTox 0.2.0 | ||
|
||
* Initial CRAN submission. |
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,78 @@ | ||
#' Set population data | ||
#' | ||
#' @param x GeoTox object. | ||
#' @param age numeric vector or list of numeric vectors of age values. | ||
#' @param obesity character vector or list of character vectors of obesity | ||
#' status. | ||
#' | ||
#' @return The same object with simulated fields added. | ||
#' @export | ||
#' | ||
#' @examples | ||
#' # Single region | ||
#' age <- round(runif(10, 1, 100)) | ||
#' obesity <- sample(c("Normal", "Obese"), 10, replace = TRUE) | ||
#' geoTox <- set_population(GeoTox(), age = age, obesity = obesity) | ||
#' | ||
#' # Multiple regions | ||
#' age <- list("37001" = round(runif(10, 1, 100)), | ||
#' "37007" = round(runif(8, 1, 100))) | ||
#' obesity <- list("37001" = sample(c("Normal", "Obese"), 10, replace = TRUE), | ||
#' "37007" = sample(c("Normal", "Obese"), 8, replace = TRUE)) | ||
#' geoTox <- set_population(GeoTox(), age = age, obesity = obesity) | ||
set_population <- function(x, age = NULL, obesity = NULL) { | ||
|
||
set_age <- !is.null(age) | ||
set_obesity <- !is.null(obesity) | ||
|
||
if (set_age) { | ||
age <- .check_types(age, | ||
c("numeric", "integer"), | ||
paste0("`age` must be a numeric vector or list of ", | ||
"numeric vectors")) | ||
} | ||
|
||
if (set_obesity) { | ||
obesity <- .check_types(obesity, | ||
"character", | ||
paste0("`obesity` must be a character vector or ", | ||
"list of character vectors")) | ||
if (any(purrr::map_lgl(obesity, | ||
\(x) !all(x %in% c("Normal", "Obese"))))) { | ||
stop("`obesity` values must be 'Normal' or 'Obese'", call. = FALSE) | ||
} | ||
} | ||
|
||
# Update population size | ||
if (set_age) n_age <- purrr::map_int(age, length) | ||
if (set_obesity) n_obesity <- purrr::map_int(obesity, length) | ||
if (set_age & set_obesity) { | ||
if (!identical(n_age, n_obesity)) { | ||
stop("Population sizes for `age` and `obesity` do not match", | ||
call. = FALSE) | ||
} | ||
x$par$n <- n_age | ||
} else if (set_age) { | ||
x$par$n <- n_age | ||
} else if (set_obesity) { | ||
x$par$n <- n_obesity | ||
} | ||
|
||
# Set fields | ||
if (set_age) x$age <- age | ||
if (set_obesity) x$obesity <- obesity | ||
|
||
# Clear downstream fields | ||
if (set_age & !is.null(x$IR)) { | ||
warning("Clearing `IR` field", call. = FALSE) | ||
x$IR <- NULL | ||
} | ||
if ((set_age | set_obesity) & | ||
!(is.null(x$C_ss) & is.null(x$css_sensitivity))) { | ||
warning("Clearing `C_ss` and `css_sensitivity` fields", call. = FALSE) | ||
x$C_ss <- NULL | ||
x$css_sensitivity <- NULL | ||
} | ||
|
||
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.