Skip to content

Commit

Permalink
count_days function
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewallenbruce committed Mar 18, 2024
1 parent 9927aa8 commit a27eca4
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Imports:
collapse
Suggests:
fontawesome,
clock,
janitor,
gluedown,
gt,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export(case_status)
export(case_supervision)
export(case_team)
export(case_tos)
export(count_days)
export(descriptors)
export(display_long)
export(gpci)
Expand Down
1 change: 1 addition & 0 deletions R/generated-globals.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ utils::globalVariables(c(
# <case_status>
# <case_asc>
# <case_coverage>
# <count_days>
":=",
# <level2>
"asc",
Expand Down
21 changes: 21 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,24 @@ display_long <- function(df, cols = dplyr::everything()) {
single_line_string <- function(x) {
stringr::str_remove_all(x, r"(\n\s*)")
}

#' Count days between two dates
#'
#' @param df data frame
#' @param start date column
#' @param end date column
#' @param name name of output column
#' @return A [tibble][tibble::tibble-package]
#' @autoglobal
#' @keyword internal
#' @export
#' @examples
#' dplyr::tibble(id = 1:3,
#' dos = as.Date(c("2021-04-18", "2021-11-18", "2022-02-18")),
#' signed = as.Date("2022-02-18")) |>
#' count_days(start = dos, end = signed, provider_lag)
count_days <- function(df, start, end, name) {
df |>
dplyr::mutate({{ name }} := clock::date_count_between({{ start }},
{{ end }}, "day"), .after = {{ end }})
}
29 changes: 29 additions & 0 deletions man/count_days.Rd

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

0 comments on commit a27eca4

Please sign in to comment.