Skip to content

Commit

Permalink
chore: updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewallenbruce committed May 21, 2024
1 parent d0b1e9a commit 0a2e761
Show file tree
Hide file tree
Showing 17 changed files with 399 additions and 595 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ Imports:
pins,
rlang,
santoku,
tidyr,
vctrs,
wakefield
Suggests:
covr,
tidyr,
ggplot2,
headliner,
forcats,
scales,
fuimus,
Expand Down
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# Generated by roxygen2: do not edit by hand

export(age_days)
export(avg_dar)
export(bin_aging)
export(count_days)
export(dar_ex)
export(generate_data)
export(load_ex)
Expand Down
12 changes: 0 additions & 12 deletions R/aging.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,5 @@ bin_aging <- function(df, date, bin_type = "chop") {
)
)
}

# if (bin_type == "ivs") {
# start <- seq(0, 120, 30)
# end <- start + 30
# end[5] <- 1000
#
# df <- df |>
# dplyr::mutate(
# aging_bin = ivs::iv(start, end)
# )
# }

return(df)
}
2 changes: 0 additions & 2 deletions R/generated-globals.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

utils::globalVariables(c(
# <avg_dar>
# <count_days>
# <age_days>
# <sorted_bars>
":=",
# <avg_dar>
Expand Down
100 changes: 4 additions & 96 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ generate_data <- function(rows = 100){
claim_id = wakefield::id(n = rows),
date_of_service = wakefield::date_stamp(
n = rows,
start = lubridate::today() - lubridate::dyears(2),
start = lubridate::today() - lubridate::dyears(1),
random = TRUE),
payer = fixtuRes::set_vector(
rows,
Expand All @@ -102,104 +102,12 @@ generate_data <- function(rows = 100){
date_of_release = date_of_service + round(abs(stats::rnorm(length(date_of_service), 11, 4))),
date_of_submission = date_of_release + round(abs(stats::rnorm(length(date_of_release), 2, 2))),
date_of_acceptance = date_of_submission + round(abs(stats::rnorm(length(date_of_submission), 3, 2))),
date_of_adjudication = date_of_acceptance + round(abs(stats::rnorm(length(date_of_acceptance), 30, 3)))) |>
tidyr::nest(dates = tidyr::contains("date"))
date_of_adjudication = date_of_acceptance + round(abs(stats::rnorm(length(date_of_acceptance), 30, 3))))
# |>
# tidyr::nest(dates = tidyr::contains("date"))

}

#' Count days between two dates
#'
#' @param df data frame
#'
#' @param start date column
#'
#' @param end date column
#'
#' @param name name of output column
#'
#' @returns A [tibble][tibble::tibble-package]
#'
#' @examples
#' generate_data(rows = 5) |>
#' tidyr::unnest(dates) |>
#' count_days(date_of_service,
#' date_of_release,
#' provider_lag)
#'
#' @autoglobal
#'
#' @export
count_days <- function(df, start, end = lubridate::today(), name) {
df |>
dplyr::mutate(
{{ name }} := clock::date_count_between(
{{ start }},
{{ end }},
"day"),
.after = {{ end }}
)
}

#' Calculate Number of Days Between Two Dates
#'
#' @note This calculation includes the end date in the sum (see example)
#'
#' @param df data frame containing date columns
#'
#' @param start column containing date(s) prior to end_date column
#'
#' @param end column containing date(s) after start_date column
#'
#' @param colname desired column name of output; default is "age"
#'
#' @returns A [tibble][tibble::tibble-package] with a named column
#' containing the calculated number of days.
#'
#' @examples
#' date_ex <- dplyr::tibble(x = seq.Date(as.Date("2021-01-01"),
#' by = "month", length.out = 3),
#' y = seq.Date(as.Date("2022-01-01"),
#' by = "month", length.out = 3))
#'
#' age_days(df = date_ex,
#' start = x,
#' end = y)
#'
#' date_ex |>
#' age_days(x,
#' y,
#' colname = "days_between_x_y")
#'
#' date_ex |>
#' age_days(start = x,
#' end = lubridate::today(),
#' colname = "days_since_x")
#'
#' date_ex |>
#' age_days(x, y, "days_between_x_y") |>
#' age_days(x, lubridate::today(), "days_since_x") |>
#' age_days(y, lubridate::today(), colname = "days_since_y")
#'
#' @autoglobal
#'
#' @export
age_days <- function(df,
start,
end,
colname = "age") {

stopifnot(inherits(df, "data.frame"))

df |>
dplyr::mutate(
start = as.Date({{ start }}, "%yyyy-%mm-%dd", tz = "EST"),
end = as.Date({{ end }}, "%yyyy-%mm-%dd", tz = "EST")
) |>
dplyr::mutate(
"{colname}" := ((as.numeric(lubridate::days(end) - lubridate::days(start), "hours") / 24) + 1)) |>
dplyr::select(!c(end, start))
}

#' Sorted Bar Chart
#'
#' @param df data frame
Expand Down
Loading

0 comments on commit 0a2e761

Please sign in to comment.