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 #2001 Added processing for missing age_units in compute_age_years #2009

Merged
merged 14 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +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).

## Breaking Changes
- The following functions, which were deprecated in previous `{admiral}` versions, have been removed: (#1950)
Expand Down
19 changes: 14 additions & 5 deletions R/compute_age_years.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
#' as `"years"` and `"Years"`).
#'
#' Permitted Values: `"years"`, `"months"`, `"weeks"`, `"days"`, `"hours"`, `"minutes"`,
#' `"seconds"`.
#' `"seconds", NA_character_`.
manciniedoardo marked this conversation as resolved.
Show resolved Hide resolved
#'
#' @details Returns a numeric vector of ages in years as doubles. Note, underlying
#' computations assume an equal number of days in each year (365.25).
#' @details Returns a numeric vector of ages in years as doubles. Note
#' that passing `NA_character_` as a unit will result in an `NA` value for the outputted
#' age. Also note, underlying computations assume an equal number of days in each
#' year (365.25).
#'
#' @return The ages contained in `age` converted to years.
#'
Expand All @@ -34,8 +36,8 @@
#' )
#'
#' compute_age_years(
#' age = c(10, 520, 3650),
#' age_unit = c("YEARS", "WEEKS", "DAYS")
#' age = c(10, 520, 3650, 1000),
#' age_unit = c("YEARS", "WEEKS", "DAYS", NA_character_)
#' )
#'
compute_age_years <- function(age,
Expand All @@ -57,6 +59,13 @@ 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"
}
}
manciniedoardo marked this conversation as resolved.
Show resolved Hide resolved

age_years <- time_length(
duration(age,
units = tolower(age_unit)
Expand Down
26 changes: 0 additions & 26 deletions docs/pkgdown.yml

This file was deleted.

12 changes: 7 additions & 5 deletions man/compute_age_years.Rd

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

6 changes: 3 additions & 3 deletions tests/testthat/test-compute_age_years.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ test_that("compute_age_years Test 1: compute_age_years() works when `age_unit` i

## Test 2: compute_age_years() works when `age_unit` is a vector ----
test_that("compute_age_years Test 2: compute_age_years() works when `age_unit` is a vector", {
age_input <- c(28, 1461, 10227)
age_unit_input <- c("YEARS", "WEEKS", "DAYS")
age_input <- c(28, 1461, 10227, 32)
age_unit_input <- c("YEARS", "WEEKS", "DAYS", NA_character_)

expected_output <- rep(28, 3)
expected_output <- c(28, 28, 28, NA)

expect_equal(
compute_age_years(
Expand Down