generated from pharmaverse/admiraltemplate
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* (#31): wrapper functions for waist/hip and waist/height ratio * (#31): Apply styler::style_file() to R-files * (#31): Fix lintr warnings + Roxygenize * (#31): Move derive_param_ratio to {admiral} * #31 Get derive_param_ratio back as not exported * #31 Fix style and update WORDLIST * (#31): Units conversion on the fly * (#31): Removed hyphens from PARAM and added a couple of unit tests * #31 Get rid of {units} package * (#31): Update keywords * Update R/derive_advs_params.R Co-authored-by: Edoardo Mancini <[email protected]> * Apply suggestions from code review Co-authored-by: Edoardo Mancini <[email protected]> * Addressed review comments * Remove my_first_fcn * Updated WORDLIST * Update as per review comments * Apply suggestions from code review Co-authored-by: Anders Askeland <[email protected]> * Update as per review comments * Fix broken code after applying suggestion from code review * Update as per review comments * Update WORDLIST * Refined code/documentation and added more tests * Added conversion factors in documentation * Apply suggestions from code review Co-authored-by: Edoardo Mancini <[email protected]> * Roxygenize after applying suggestions from code review * Fix lintr issues after applying suggestions from code review * Unit tests for get_conv_factor * One more test to reach 100% test coverage --------- Co-authored-by: Edoardo Mancini <[email protected]> Co-authored-by: Anders Askeland <[email protected]>
- Loading branch information
1 parent
f29b18d
commit 6f18ffe
Showing
21 changed files
with
1,914 additions
and
86 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
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,63 @@ | ||
#' Asserts That a Parameter is Provided in One of the Expected Units | ||
#' | ||
#' @description | ||
#' `r lifecycle::badge("deprecated")` | ||
#' | ||
#' This function is to be *deprecated*. Please use `admiraldev::assert_unit()` instead | ||
#' once https://github.com/pharmaverse/admiraldev/issues/468 is closed. | ||
#' | ||
#' @inherit admiraldev::assert_unit | ||
#' | ||
#' @seealso [admiraldev::assert_unit] | ||
#' | ||
#' @examples | ||
#' # See examples of `admiraldev::assert_unit` | ||
#' | ||
#' @family internal deprecated | ||
#' @keywords internal deprecated | ||
assert_unit <- function(dataset, | ||
param, | ||
required_unit, | ||
get_unit_expr, | ||
arg_name = rlang::caller_arg(required_unit), | ||
message = NULL, | ||
class = "assert_unit", | ||
call = parent.frame()) { | ||
assert_data_frame(dataset, required_vars = exprs(PARAMCD)) | ||
assert_character_scalar(param) | ||
assert_character_vector(required_unit) | ||
get_unit_expr <- enexpr(get_unit_expr) | ||
|
||
units <- dataset %>% | ||
mutate(tmp_unit = !!get_unit_expr) %>% | ||
filter(PARAMCD == param & !is.na(.data$tmp_unit)) %>% | ||
pull(.data$tmp_unit) %>% | ||
unique() | ||
|
||
if (length(units) != 1L) { | ||
message <- | ||
message %||% | ||
"Multiple units {.val {units}} found for {.val {param}}. Please review and update the units." | ||
|
||
cli_abort( | ||
message = message, | ||
call = call, | ||
class = c(class, "assert-admiraldev") | ||
) | ||
} | ||
|
||
if (tolower(units) %notin% tolower(required_unit)) { | ||
message <- | ||
message %||% | ||
"It is expected that {.val {param}} has unit of {.or {required_unit}}. | ||
In the input dataset the unit is {.val {units}}." | ||
|
||
cli_abort( | ||
message = message, | ||
call = call, | ||
class = c(class, "assert-admiraldev") | ||
) | ||
} | ||
|
||
invisible(dataset) | ||
} |
Oops, something went wrong.