From e41a87eee507e46a5bb5474cb58a66ff9e5acc23 Mon Sep 17 00:00:00 2001 From: "Mancini, Edoardo {MDBB~Welwyn}" Date: Wed, 19 Jul 2023 13:41:44 +0200 Subject: [PATCH] #2001 - removed for loop, changed unit in `derive_vars_aage`, restored `docs/pkgdown.yml`. --- NEWS.md | 2 +- R/compute_age_years.R | 14 +++++++------- R/derive_vars_aage.R | 8 ++++---- docs/pkgdown.yml | 26 ++++++++++++++++++++++++++ man/derive_vars_aage.Rd | 4 ++-- 5 files changed, 40 insertions(+), 14 deletions(-) create mode 100644 docs/pkgdown.yml diff --git a/NEWS.md b/NEWS.md index a033778557..af1e592f72 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,7 +4,7 @@ ## Updates of Existing Functions - The functions `derive_param_bmi()` and `derive_param_bsa()` are updated to have the option of producing more values at visits when only weight is collected (#1228). -- The functions `derive_var_age_years` and `compute_age_years` are updated to return an `NA` age in the case that the age unit is missing (#2001). +- The functions `derive_var_age_years` and `compute_age_years` are updated to return an `NA` age in the case that the age unit is missing. The argument `unit` for `derive_vars_aage` is also changed to `age_unit` for consistency between these age-related functions (#2001). ## Breaking Changes - The following functions, which were deprecated in previous `{admiral}` versions, have been removed: (#1950) diff --git a/R/compute_age_years.R b/R/compute_age_years.R index d847a506db..6a16759af0 100644 --- a/R/compute_age_years.R +++ b/R/compute_age_years.R @@ -59,16 +59,16 @@ compute_age_years <- function(age, )) } - for (i in seq_along(age_unit)) { - if (is.na(age_unit[i])) { - age[i] <- NA - age_unit[i] <- "years" - } + if (length(age_unit) == 1){ + age_unit_rep <- rep(age_unit, length(age)) + }else{ + age_unit_rep <- age_unit } age_years <- time_length( - duration(age, - units = tolower(age_unit) + duration( + num = if_else(is.na(age_unit_rep), NA_real_, age), + units = if_else(is.na(age_unit_rep), "years", tolower(age_unit_rep)) ), unit = "years" ) diff --git a/R/derive_vars_aage.R b/R/derive_vars_aage.R index c8c041562c..c103486422 100644 --- a/R/derive_vars_aage.R +++ b/R/derive_vars_aage.R @@ -27,7 +27,7 @@ #' #' Default: `RANDDT` #' -#' @param unit Unit +#' @param age_unit Age unit #' #' The age is derived in the specified unit #' @@ -64,12 +64,12 @@ derive_vars_aage <- function(dataset, start_date = BRTHDT, end_date = RANDDT, - unit = "years") { + age_unit = "years") { start_date <- assert_symbol(enexpr(start_date)) end_date <- assert_symbol(enexpr(end_date)) assert_data_frame(dataset, required_vars = expr_c(start_date, end_date)) assert_character_scalar( - unit, + age_unit, values = c("years", "months", "weeks", "days", "hours", "minutes", "seconds") ) @@ -79,7 +79,7 @@ derive_vars_aage <- function(dataset, new_var_unit = AAGEU, start_date = !!start_date, end_date = !!end_date, - out_unit = unit, + out_unit = age_unit, add_one = FALSE, trunc_out = TRUE ) diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml new file mode 100644 index 0000000000..c8fbfc66fe --- /dev/null +++ b/docs/pkgdown.yml @@ -0,0 +1,26 @@ +pandoc: 2.11.4 +pkgdown: 2.0.7 +pkgdown_sha: ~ +articles: + admiral: admiral.html + adsl: adsl.html + bds_exposure: bds_exposure.html + bds_finding: bds_finding.html + bds_tte: bds_tte.html + contribution_model: contribution_model.html + faq: faq.html + generic: generic.html + higher_order: higher_order.html + hys_law: hys_law.html + imputation: imputation.html + lab_grading: lab_grading.html + occds: occds.html + pk_adnca: pk_adnca.html + queries_dataset: queries_dataset.html + questionnaires: questionnaires.html + visits_periods: visits_periods.html +last_built: 2023-07-19T10:42Z +urls: + reference: https://pharmaverse.github.io/admiral/reference + article: https://pharmaverse.github.io/admiral/articles + diff --git a/man/derive_vars_aage.Rd b/man/derive_vars_aage.Rd index 6c43f19929..8eb08b1cb3 100644 --- a/man/derive_vars_aage.Rd +++ b/man/derive_vars_aage.Rd @@ -8,7 +8,7 @@ derive_vars_aage( dataset, start_date = BRTHDT, end_date = RANDDT, - unit = "years" + age_unit = "years" ) } \arguments{ @@ -35,7 +35,7 @@ vector to a date object. Default: \code{RANDDT}} -\item{unit}{Unit +\item{age_unit}{Age unit The age is derived in the specified unit