Skip to content

Commit

Permalink
#2001 - removed for loop, changed unit in derive_vars_aage, restore…
Browse files Browse the repository at this point in the history
…d `docs/pkgdown.yml`.
  • Loading branch information
manciniedoardo committed Jul 19, 2023
1 parent 0650f64 commit e41a87e
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 14 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions R/compute_age_years.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
8 changes: 4 additions & 4 deletions R/derive_vars_aage.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#'
#' Default: `RANDDT`
#'
#' @param unit Unit
#' @param age_unit Age unit
#'
#' The age is derived in the specified unit
#'
Expand Down Expand Up @@ -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")
)

Expand All @@ -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
)
Expand Down
26 changes: 26 additions & 0 deletions docs/pkgdown.yml
Original file line number Diff line number Diff line change
@@ -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

4 changes: 2 additions & 2 deletions man/derive_vars_aage.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e41a87e

Please sign in to comment.