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

Age on Date #10

Merged
merged 6 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Build Package and vignette added
  • Loading branch information
i-scherr committed Sep 9, 2024
commit 431e8c3f9abd7384097c4eae1064d19593ea5a22
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Description: Useful helper functions designed for use in Social Security Scotlan
License: MIT + file LICENSE
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Imports:
bizdays,
dplyr,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

export("%>%")
export(adorn_financial_years)
export(age_on_date)
export(bucket_other)
export(convert_col_date)
export(convert_date)
Expand Down
4 changes: 2 additions & 2 deletions R/date_tools.R
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,12 @@ create_sss_calendar <- function(date_from = "2018-01-01", date_to = "2070-01-01"
#' Calculate age in years using two dates
#'
#' This function calculates the age someone would be between a date of birth and a given date,
#' # either single date or column of dates
#' either single date or column of dates
#' @param date_column Column for Date of Birth
#' @param reference_date Date or column of dates to calculate age on
#' @export

calculate_age_on_date <- function(date_column, reference_date) {
age_on_date <- function(date_column, reference_date) {
# Convert dates to Date objects
date_column <- as.Date(date_column)
reference_date <- as.Date(reference_date)
Expand Down
17 changes: 17 additions & 0 deletions man/age_on_date.Rd

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

18 changes: 18 additions & 0 deletions vignettes/date_tools.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,21 @@ data %>%
print(n = 30)

```
## Calulating age on date
The function `age_on_date()` can be used to calculate the age someone will be on a given date, either as a single reference date, or a matching column of dates compared to their date of birth.

```{r example data, echo = FALSE}
data = tibble(
dob = c(ymd("1990-01-13"),ymd("2002-04-08"),ymd("1987-08-03"),ymd("2008-12-24"),ymd("2002-05-15")),
application_date = c(ymd("2021-03-04"),ymd("2022-07-08"),ymd("2022-11-11"),ymd("2023-02-28"),ymd("2023-07-01"))
)
```

```{r show example data}
data

data$'Age on Application Date' <- age_on_date(data$dob, data$application_date)
data$'Age on Christmas 2023' <- age_on_date(data$dob, ymd("2023-12-25"))

data
```