Skip to content

Commit

Permalink
Removed dependency on dint (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewallenbruce committed Nov 5, 2023
1 parent 1de24d0 commit bb96515
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 28 deletions.
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ Depends:
Imports:
anytime,
cli,
dint,
dplyr,
furrr,
httr2,
Expand Down
2 changes: 1 addition & 1 deletion R/beneficiaries.R
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ beneficiaries <- function(year = NULL,

results <- httr2::resp_body_json(response, simplifyVector = TRUE)

if (tidy) results <- cols_bene(tidyup(results, int = c("year", "_benes"), yr = 'year'))
if (tidy) results <- cols_bene(tidyup(results, int = c('year', '_benes')))
if (!is.null(period) && period == "Month") results <- dplyr::filter(results, period %in% month.name)

return(results)
Expand Down
3 changes: 1 addition & 2 deletions R/conditions.R
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,7 @@ conditions <- function(year,
results$year <- year
results <- cols_cc(tidyup(results,
int = "year",
dbl = c("prvlnc", "_pc", "er_"),
yr = "year"))
dbl = c("prvlnc", "_pc", "er_")))
if (na.rm) {results <- narm(results)}}
return(results)
}
Expand Down
3 changes: 1 addition & 2 deletions R/open_payments.R
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,7 @@ open_payments <- function(year,
results <- tidyup(results,
# yn = c(yncols),
dbl = "dollars",
int = "program_year",
yr = "program_year") |>
int = "program_year") |>
dplyr::mutate(change_type = changed_logical(change_type),
covered_recipient_type = covered_recipient(covered_recipient_type),
nature_of_payment_or_transfer_of_value = nature(nature_of_payment_or_transfer_of_value)) |>
Expand Down
3 changes: 1 addition & 2 deletions R/outpatient.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ outpatient <- function(year,
dbl = c('avg_tot_sbmtd_chrgs',
'avg_mdcr_alowd_amt',
'avg_mdcr_pymt_amt',
'avg_mdcr_outlier_amt'),
yr = 'year') |>
'avg_mdcr_outlier_amt')) |>
cols_out()
if (na.rm) results <- narm(results)
}
Expand Down
4 changes: 2 additions & 2 deletions R/quality_payment.R
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ quality_payment <- function(year,
"pi_bonus",
"extreme_hardship_ia",
"ia_study",
"extreme_hardship_cost"),
yr = 'year') |> cols_qpp("tidy")
"extreme_hardship_cost")) |>
cols_qpp("tidy")

if (nest) {
pcol <- list(q = c('quality_measure_id_', 'quality_measure_score_') %s+% rep(1:10, each = 2),
Expand Down
9 changes: 3 additions & 6 deletions R/utilization.R
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,7 @@ tidyup_provider <- function(results, nest, detailed) {
int = c("year", "_hcpcs", "bene", "_srvcs"),
dbl = c("pay", "pymt", "charges", "allowed", "cc_", "hcc"),
cred = "credential",
ent = "entity_type",
yr = 'year') |>
ent = "entity_type") |>
combine(address, c('rndrng_prvdr_st1', 'rndrng_prvdr_st2')) |>
dplyr::mutate(specialty = correct_specialty(specialty),
.copay_deduct = tot_allowed - tot_payment,
Expand Down Expand Up @@ -318,8 +317,7 @@ tidyup_service <- function(results, rbcs) {
results <- tidyup(results,
yn = "_ind",
int = c("year", "tot_"),
dbl = "avg_",
yr = 'year') |>
dbl = "avg_") |>
combine(address, c('rndrng_prvdr_st1', 'rndrng_prvdr_st2')) |>
cols_util("service") |>
dplyr::mutate(specialty = correct_specialty(specialty))
Expand All @@ -339,8 +337,7 @@ tidyup_geography <- function(results, rbcs) {
results <- tidyup(results,
yn = "_ind",
int = c("year", "tot_"),
dbl = "avg_",
yr = 'year') |>
dbl = "avg_") |>
dplyr::mutate(place_of_srvc = pos_char(place_of_srvc)) |>
cols_util("geography")

Expand Down
5 changes: 1 addition & 4 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ df2chr <- function(df) {
#' @param up cols to convert to upper case
#' @param cred cols to remove periods from
#' @param ent cols to convert to NPI entity type
#' @param yr cols to convert to year with [dint::as_date_y()]
#' @returns tidy data frame
#' @autoglobal
#' @export
Expand All @@ -172,8 +171,7 @@ tidyup <- function(df,
chr = NULL,
up = NULL,
cred = NULL,
ent = NULL,
yr = NULL) {
ent = NULL) {

x <- janitor::clean_names(df) |>
dplyr::tibble() |>
Expand All @@ -191,7 +189,6 @@ tidyup <- function(df,
if (!is.null(up)) {x <- dplyr::mutate(x, dplyr::across(dplyr::contains(up), toupper))}
if (!is.null(cred)) {x <- dplyr::mutate(x, dplyr::across(dplyr::contains(cred), clean_credentials))}
if (!is.null(ent)) {x <- dplyr::mutate(x, dplyr::across(dplyr::contains(ent), entype_char))}
if (!is.null(yr)) {x <- dplyr::mutate(x, dplyr::across(dplyr::any_of(yr), dint::as_date_y))}
return(x)
}

Expand Down
5 changes: 1 addition & 4 deletions man/tidyup.Rd

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

6 changes: 2 additions & 4 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ test_that("display_long() works", {
test_that("tidyup() works", {
df <- dplyr::tibble(
name = "John Doe ",
year = "1981",
date = "1981/03/07",
int = "123456789",
dbl = "12.34",
Expand All @@ -68,7 +67,6 @@ test_that("tidyup() works", {

tidy <- dplyr::tibble(
name = "JOHN DOE",
year = dint::as_date_y(1981),
date = anytime::anydate("1981/03/07"),
int = 123456789,
dbl = 12.34,
Expand All @@ -82,8 +80,8 @@ test_that("tidyup() works", {
dash = NA_character_)

expect_equal(tidyup(df, yn = "yn", int = c("int", "year"),
dbl = "dbl", yr = "year", up = "name",
cred = "cred", ent = c("ind", "org")), tidy)
dbl = "dbl", up = "name", cred = "cred",
ent = c("ind", "org")), tidy)
})

test_that("combine() works", {
Expand Down

0 comments on commit bb96515

Please sign in to comment.