R/descriptive_analyses.R

Defines functions name_time_buckets

require(pacman)
pkgs <- c('tidyverse', 'data.table', 'rquery', 'testit', 'janitor')

p_load(char = pkgs)



# Params ------------------------------------------------------------------
#this section hosts user supplied paramaters
directory          <- "C:\\Users\\EG945HC\\OneDrive - EY\\Projects\\20191115 Acute Care Analysis\\Data\\"
file_in            <- "datafile.csv"
service_data      <- "2019-06-30" %>% as.Date()
time_buckets_start <- c(0, 31, 61, 91, 121, 151, 181, 366)
time_buckets_end   <- c(30, 60, 90, 120, 150, 180, 365, 10^5)
group_vars         <- c('site_state', 'site_type', 'site_mnem', 'current_primary_group')

# Functions ---------------------------------------------------------------
#' Automate creation of time bucket names for AR analysis
#'
#' @param time_buckets_start A vector of numerics indicating the start of a time bucket
#' @param time_buckets_end A vector of numerics indicating the end of a time bucket
#' @return A character vector of time bucket names
name_time_buckets <- function(time_buckets_start, time_buckets_end){
  # creates bucket names automatically
  testit::assert(length(time_buckets_start) %==% length(time_buckets_end))
  testit::assert(time_buckets_start < time_buckets_end)

  n <- length(time_buckets_start)
  out <- c()
  for(i in 1:n){
    if(i == n){
      out <- c(out, glue::glue("({i}) {time_buckets_start[i]}+ Days"))
    } else {
      out <- c(out, glue::glue("({i}) {time_buckets_start[i]}-{time_buckets_end[i]} Days"))
    }
  }
  out
}


#' New lost existing analysis
#'
#' @param time_buckets_start A vector of numerics indicating the start of a time bucket
#' @param time_buckets_end A vector of numerics indicating the end of a time bucket
#' @param time_buckets_name A character vector of time bucket names (eg. FY2019, LTM2019)
#' @return A character vector of time bucket names


# Data Ingest -------------------------------------------------------------

df <- fread(paste0(directory, file_in))
df <- clean_names(df)
prescient/opinionated_pipelines documentation built on Dec. 10, 2019, 12:15 a.m.