Skip to content

Commit

Permalink
added date regex to common_regex (closes #7)
Browse files Browse the repository at this point in the history
refactored mock data generators
  • Loading branch information
andrewallenbruce committed Dec 13, 2024
1 parent a972f7e commit 6e2d6db
Show file tree
Hide file tree
Showing 13 changed files with 141 additions and 171 deletions.
4 changes: 2 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export(duration_vec)
export(expand_date_range)
export(fancy_ts)
export(find_common_order)
export(forager_data)
export(gchop)
export(geomean)
export(get_pin)
Expand All @@ -56,6 +55,8 @@ export(is_valid_npi)
export(is_valid_npi2)
export(list_pins)
export(make_interval)
export(mock_forager)
export(mock_provider)
export(mount_board)
export(na_if_common)
export(named_group_split)
Expand All @@ -66,7 +67,6 @@ export(percentage_calculator)
export(percentage_change)
export(percentage_difference)
export(print_ls)
export(provider_data)
export(random_npi_generator)
export(rate_of_return)
export(remove_quiet)
Expand Down
8 changes: 4 additions & 4 deletions R/describe.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#' @returns `<tibble>` of summary statistics
#'
#' @examples
#' describe(fuimus:::provider_data(2000:2020))
#' describe(mock_provider(2000:2020))
#'
#' describe(fuimus:::forager_data(200), !dplyr::starts_with("date"))
#' describe(mock_forager(200), !dplyr::starts_with("date"))
#'
#' @autoglobal
#'
Expand Down Expand Up @@ -140,9 +140,9 @@ histo <- function(x, width = 10) {
#'
#' @examples
#'
#' describe_unique(fuimus:::forager_data(), claim_id, payer)
#' describe_unique(mock_forager(), ins_class, payer)
#'
#' # describe_unique(fuimus:::forager_data(200), names(df)[2:3])
#' # describe_unique(mock_forager(200), names(df)[2:3])
#'
#' @autoglobal
#'
Expand Down
99 changes: 0 additions & 99 deletions R/generate_data.R

This file was deleted.

63 changes: 63 additions & 0 deletions R/mock.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#' Generate simple data frame for testing
#'
#' @param years `<int>` vector (`c(2020, 2021, 2023)`) or sequence of years
#' (`2010:2020`)
#'
#' @returns A [tibble][tibble::tibble-package] containing the search results.
#'
#' @examples
#' mock_provider(2010:2020)
#'
#' mock_provider(c(2020, 2021, 2023))
#'
#' @autoglobal
#'
#' @family mock
#'
#' @export
mock_provider <- \(years) {

lng <- length(years)

dplyr::tibble(
year = rep.int(years, 2),
group = rep(c("A", "B"), each = lng),
payment = sample(10000:20000, lng * 2))
}

#' Generate mock coding/billing data frame
#'
#' @param rows `<int>` number of rows to generate; default is 10
#'
#' @param nest `<lgl>` whether to nest the dates column; default is `TRUE`
#'
#' @returns A [tibble][tibble::tibble-package]
#'
#' @examples
#' mock_forager(rows = 5)
#'
#' @autoglobal
#'
#' @family mock
#'
#' @export
mock_forager <- function(rows = 10, nest = TRUE){

payer_names <- c("Medicare", "Medicaid", "Cigna", "Humana", "UHC", "Anthem", "BCBS", "Centene")

x <- dplyr::tibble(
claim_id = as.character(wakefield::id(n = rows)),
date_of_service = wakefield::dob(n = rows, start = Sys.Date() - 730, random = TRUE, k = 12, by = "-1 months"),
payer = fixtuRes::set_vector(rows, set = payer_names),
ins_class = fixtuRes::set_vector(rows, set = c("Primary", "Secondary")),
balance = as.double(wakefield::income(n = rows, digits = 2) / 300),
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))))

if (nest)
return(tidyr::nest(x, dates = tidyr::contains("date")))

x
}
8 changes: 6 additions & 2 deletions R/regex.R
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ pos_nchar <- function(x) {
#' @autoglobal
#'
#' @export
common_regex <- function(x = c("month_date", "month", "url")) {
common_regex <- function(x = c("month_date", "month", "url", "date")) {

x <- match.arg(x)

Expand All @@ -241,8 +241,12 @@ common_regex <- function(x = c("month_date", "month", "url")) {
\u00a1-\uffff](?:-)*)*(?:[a-z0-9\u00a1-\uffff])+)(?:\\.(?:[a-z0-9
\u00a1-\uffff](?:-)*)*(?:[a-z0-9\u00a1-\uffff])+)*(?:\\.(?:[a-z0-9
\u00a1-\uffff]){2,})(?::(?:\\d){2,5})?(?:/(?:\\S)*)?$"
),
date = single_line_string(
"\\b\\d{4}[-/]\\d{2}[-/]\\d{2}\\b|\\b\\d{2}[-/]\\d{2}[-/]\\d{4}\\b|
\\d{6}|\\b\\d{1,2}[-/.]\\d{1,2}[-/.]\\d{2,4}\\b"
)
)
)

reg[[x]]
}
2 changes: 1 addition & 1 deletion man/common_regex.Rd

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

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

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

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

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

30 changes: 0 additions & 30 deletions man/forager_data.Rd

This file was deleted.

29 changes: 29 additions & 0 deletions man/mock_forager.Rd

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

30 changes: 30 additions & 0 deletions man/mock_provider.Rd

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

27 changes: 0 additions & 27 deletions man/provider_data.Rd

This file was deleted.

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

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

0 comments on commit 6e2d6db

Please sign in to comment.