Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #31 wrapper functions for waist/hip and waist/height ratio #33

Merged
merged 28 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
52edc04
(#31): wrapper functions for waist/hip and waist/height ratio
yurovska Sep 28, 2024
91f76c3
(#31): Apply styler::style_file() to R-files
yurovska Sep 28, 2024
2ce6436
(#31): Fix lintr warnings + Roxygenize
yurovska Sep 28, 2024
be8ea17
(#31): Move derive_param_ratio to {admiral}
yurovska Oct 1, 2024
8753a73
#31 Get derive_param_ratio back as not exported
yurovska Oct 9, 2024
fddb8c3
#31 Fix style and update WORDLIST
yurovska Oct 10, 2024
1685761
(#31): Units conversion on the fly
yurovska Oct 10, 2024
ccdf002
(#31): Removed hyphens from PARAM and added a couple of unit tests
yurovska Oct 11, 2024
eaa6524
#31 Get rid of {units} package
yurovska Oct 15, 2024
0fd9e8f
(#31): Update keywords
yurovska Oct 20, 2024
37cfd49
Update R/derive_advs_params.R
yurovska Oct 23, 2024
84f39c4
Apply suggestions from code review
yurovska Oct 23, 2024
8024de2
Addressed review comments
yurovska Oct 23, 2024
03f57ed
Remove my_first_fcn
yurovska Oct 23, 2024
271e2a3
Updated WORDLIST
yurovska Oct 23, 2024
75c92c7
Update as per review comments
yurovska Oct 26, 2024
5274ef0
Apply suggestions from code review
yurovska Oct 26, 2024
af058ee
Update as per review comments
yurovska Oct 26, 2024
283de12
Fix broken code after applying suggestion from code review
yurovska Oct 26, 2024
65f7d89
Update as per review comments
yurovska Oct 28, 2024
1f05f0f
Update WORDLIST
yurovska Oct 29, 2024
d745aca
Refined code/documentation and added more tests
yurovska Oct 29, 2024
888d2fa
Added conversion factors in documentation
yurovska Oct 30, 2024
d92721d
Apply suggestions from code review
yurovska Oct 30, 2024
1009e76
Roxygenize after applying suggestions from code review
yurovska Oct 30, 2024
1d649f8
Fix lintr issues after applying suggestions from code review
yurovska Oct 30, 2024
058e6a5
Unit tests for get_conv_factor
yurovska Oct 30, 2024
5908433
One more test to reach 100% test coverage
yurovska Oct 30, 2024
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
2 changes: 2 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ Depends:
Imports:
admiral (>= 1.1.1),
admiraldev (>= 1.0.0),
cli (>= 3.6.2),
dplyr (>= 0.8.4),
stringr (>= 1.4.0),
lifecycle (>= 0.1.0),
lubridate (>= 1.7.4),
magrittr (>= 1.5),
purrr (>= 0.3.3),
rlang (>= 0.4.4),
tidyselect (>= 1.0.0)
Suggests:
Expand Down
24 changes: 23 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
# Generated by roxygen2: do not edit by hand

export(hello_admiral)
export(derive_param_waisthgt)
export(derive_param_waisthip)
importFrom(admiral,derive_param_computed)
importFrom(admiraldev,"%notin%")
importFrom(admiraldev,assert_character_scalar)
importFrom(admiraldev,assert_character_vector)
importFrom(admiraldev,assert_data_frame)
importFrom(admiraldev,assert_expr)
importFrom(admiraldev,assert_filter_cond)
importFrom(admiraldev,assert_logical_scalar)
importFrom(admiraldev,assert_numeric_vector)
importFrom(admiraldev,assert_param_does_not_exist)
importFrom(admiraldev,assert_vars)
importFrom(admiraldev,assert_varval_list)
importFrom(admiraldev,expect_dfs_equal)
importFrom(cli,cli_abort)
importFrom(cli,cli_alert_info)
importFrom(dplyr,arrange)
importFrom(dplyr,bind_cols)
importFrom(dplyr,bind_rows)
Expand Down Expand Up @@ -30,6 +46,7 @@ importFrom(dplyr,summarise)
importFrom(dplyr,summarise_at)
importFrom(dplyr,tibble)
importFrom(dplyr,transmute)
importFrom(dplyr,tribble)
importFrom(dplyr,ungroup)
importFrom(dplyr,union)
importFrom(dplyr,vars)
Expand All @@ -53,6 +70,8 @@ importFrom(lubridate,years)
importFrom(lubridate,ymd)
importFrom(lubridate,ymd_hms)
importFrom(magrittr,"%>%")
importFrom(purrr,discard_at)
importFrom(rlang,"%||%")
importFrom(rlang,":=")
importFrom(rlang,.data)
importFrom(rlang,abort)
Expand All @@ -64,12 +83,14 @@ importFrom(rlang,call_name)
importFrom(rlang,caller_env)
importFrom(rlang,current_env)
importFrom(rlang,enexpr)
importFrom(rlang,enexprs)
importFrom(rlang,enquo)
importFrom(rlang,eval_bare)
importFrom(rlang,eval_tidy)
importFrom(rlang,expr)
importFrom(rlang,expr_interp)
importFrom(rlang,expr_label)
importFrom(rlang,exprs)
importFrom(rlang,f_lhs)
importFrom(rlang,f_rhs)
importFrom(rlang,inform)
Expand Down Expand Up @@ -105,6 +126,7 @@ importFrom(stringr,str_c)
importFrom(stringr,str_detect)
importFrom(stringr,str_extract)
importFrom(stringr,str_glue)
importFrom(stringr,str_glue_data)
importFrom(stringr,str_remove)
importFrom(stringr,str_remove_all)
importFrom(stringr,str_replace)
Expand Down
17 changes: 12 additions & 5 deletions R/admiralmetabolic-package.R
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
#' @keywords internal
#' @family internal
#' @importFrom admiraldev %notin% assert_numeric_vector assert_character_scalar
#' assert_logical_scalar assert_data_frame assert_vars assert_varval_list
#' assert_filter_cond assert_param_does_not_exist assert_expr expect_dfs_equal
#' assert_character_vector
#' @importFrom admiral derive_param_computed
#' @importFrom cli cli_abort cli_alert_info
#' @importFrom dplyr arrange bind_rows case_when desc ends_with filter full_join group_by
#' if_else mutate mutate_at mutate_if n pull rename rename_at row_number select slice
#' starts_with transmute ungroup vars n_distinct union distinct
#' summarise_at summarise coalesce bind_cols na_if tibble
#' summarise_at summarise coalesce bind_cols na_if tibble tribble
#' @importFrom magrittr %>%
#' @importFrom rlang := abort arg_match as_function as_string call2 caller_env
#' call_name current_env .data enexpr enquo eval_bare eval_tidy expr
#' expr_interp expr_label f_lhs f_rhs inform
#' @importFrom purrr discard_at
#' @importFrom rlang := %||% abort arg_match as_function as_string call2 caller_env
#' call_name current_env .data enexpr enexprs enquo eval_bare eval_tidy expr
#' exprs expr_interp expr_label f_lhs f_rhs inform
#' is_bare_formula is_call is_character is_formula is_integerish
#' is_logical is_quosure is_quosures is_symbol new_formula
#' parse_expr parse_exprs quo quo_get_expr quo_is_call
#' quo_is_missing quo_is_null quo_is_symbol quos quo_squash quo_text
#' set_names sym syms type_of warn quo_set_env quo_get_env
#' @importFrom utils capture.output str
#' @importFrom stringr str_c str_detect str_extract str_remove str_remove_all
#' str_replace str_trim str_to_lower str_to_title str_to_upper str_glue
#' str_replace str_trim str_to_lower str_to_title str_to_upper str_glue str_glue_data
#' @importFrom lubridate as_datetime ceiling_date date days duration floor_date is.Date is.instant
#' time_length %--% ymd ymd_hms weeks years hours minutes
#' @importFrom tidyselect all_of contains vars_select
Expand Down
63 changes: 63 additions & 0 deletions R/assertions.R
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
yurovska marked this conversation as resolved.
Show resolved Hide resolved
#'
#' @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)
}
Loading
Loading