From 787fa9381b065132c31dc076af64f6346446557f Mon Sep 17 00:00:00 2001 From: Andrew Bruce Date: Mon, 16 Dec 2024 21:22:21 -0500 Subject: [PATCH] * standalone-helpers updated --- DESCRIPTION | 2 - NAMESPACE | 44 ++++++ R/describe.R | 84 ++++++++++- R/generated-globals.R | 13 ++ R/mock.R | 52 +++++-- R/standalone-helpers.R | 308 ++++++++++++++++++++++++++++++++++------ R/tidyverse.R | 15 +- data-raw/dev/codebook.R | 118 +++++++++++++++ fuimus.Rproj | 1 + man/as_chr.Rd | 18 +++ man/as_date.Rd | 22 +++ man/as_int.Rd | 18 +++ man/as_num.Rd | 18 +++ man/combine.Rd | 11 +- man/count_prop_multi.Rd | 2 +- man/count_wide.Rd | 2 +- man/delist.Rd | 18 +++ man/describe2.Rd | 25 ++++ man/describe_unique.Rd | 8 +- man/desplit.Rd | 15 ++ man/empty.Rd | 18 +++ man/false.Rd | 18 +++ man/gelm.Rd | 24 ++++ man/getelem.Rd | 20 +++ man/if_empty_null.Rd | 18 +++ man/iif_else.Rd | 21 +++ man/invert_named.Rd | 18 +++ man/max_vlen.Rd | 18 +++ man/mock_forager.Rd | 4 +- man/na.Rd | 18 +++ man/na_if.Rd | 20 +++ man/not_na.Rd | 18 +++ man/not_null.Rd | 18 +++ man/null.Rd | 18 +++ man/random_string.Rd | 22 +++ man/remove_all_na.Rd | 18 +++ man/remove_quotes.Rd | 18 +++ man/roundup.Rd | 20 +++ man/search_in.Rd | 22 +++ man/sf_at.Rd | 20 +++ man/sf_c.Rd | 18 +++ man/sf_chars.Rd | 18 +++ man/sf_conv.Rd | 18 +++ man/sf_detect.Rd | 20 +++ man/sf_extract.Rd | 20 +++ man/sf_ndetect.Rd | 20 +++ man/sf_nextract.Rd | 20 +++ man/sf_remove.Rd | 22 +++ man/sf_replace.Rd | 24 ++++ man/sf_smush.Rd | 20 +++ man/sf_strsplit.Rd | 22 +++ man/sf_sub.Rd | 22 +++ man/strsort.Rd | 18 +++ man/true.Rd | 18 +++ man/uniq.Rd | 18 +++ man/uniq_narm.Rd | 18 +++ man/uniq_vlen.Rd | 18 +++ man/vlen.Rd | 18 +++ 58 files changed, 1430 insertions(+), 87 deletions(-) create mode 100644 data-raw/dev/codebook.R create mode 100644 man/as_chr.Rd create mode 100644 man/as_date.Rd create mode 100644 man/as_int.Rd create mode 100644 man/as_num.Rd create mode 100644 man/delist.Rd create mode 100644 man/describe2.Rd create mode 100644 man/desplit.Rd create mode 100644 man/empty.Rd create mode 100644 man/false.Rd create mode 100644 man/gelm.Rd create mode 100644 man/getelem.Rd create mode 100644 man/if_empty_null.Rd create mode 100644 man/iif_else.Rd create mode 100644 man/invert_named.Rd create mode 100644 man/max_vlen.Rd create mode 100644 man/na.Rd create mode 100644 man/na_if.Rd create mode 100644 man/not_na.Rd create mode 100644 man/not_null.Rd create mode 100644 man/null.Rd create mode 100644 man/random_string.Rd create mode 100644 man/remove_all_na.Rd create mode 100644 man/remove_quotes.Rd create mode 100644 man/roundup.Rd create mode 100644 man/search_in.Rd create mode 100644 man/sf_at.Rd create mode 100644 man/sf_c.Rd create mode 100644 man/sf_chars.Rd create mode 100644 man/sf_conv.Rd create mode 100644 man/sf_detect.Rd create mode 100644 man/sf_extract.Rd create mode 100644 man/sf_ndetect.Rd create mode 100644 man/sf_nextract.Rd create mode 100644 man/sf_remove.Rd create mode 100644 man/sf_replace.Rd create mode 100644 man/sf_smush.Rd create mode 100644 man/sf_strsplit.Rd create mode 100644 man/sf_sub.Rd create mode 100644 man/strsort.Rd create mode 100644 man/true.Rd create mode 100644 man/uniq.Rd create mode 100644 man/uniq_narm.Rd create mode 100644 man/uniq_vlen.Rd create mode 100644 man/vlen.Rd diff --git a/DESCRIPTION b/DESCRIPTION index f88d910..fb2e674 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -27,7 +27,6 @@ Suggests: clock, dplyr, fipio, - fixtuRes, fontawesome, forcats, fs (>= 1.6.5), @@ -54,7 +53,6 @@ Suggests: tidyr, timeplyr, usethis, - wakefield, zipcodeR Config/roxyglobals/filename: generated-globals.R Config/roxyglobals/unique: TRUE diff --git a/NAMESPACE b/NAMESPACE index c53147a..c8712ad 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -6,6 +6,10 @@ export("%or%") export(add_counties) export(age_days) export(arrows) +export(as_chr) +export(as_date) +export(as_int) +export(as_num) export(bracks) export(change) export(change_lagged) @@ -29,18 +33,25 @@ export(count_prop_multi) export(count_wide) export(create_vec) export(data_types) +export(delist) export(delister) export(density) export(describe) +export(describe2) export(describe_unique) +export(desplit) export(display_long) export(duration_vec) +export(empty) export(expand_date_range) +export(false) export(fancy_ts) export(find_common_order) export(gchop) +export(gelm) export(geomean) export(get_pin) +export(getelem) export(gg_theme) export(gh_raw) export(glue_chr) @@ -49,18 +60,27 @@ export(gluestick) export(gt_marks) export(histo) export(histogram) +export(if_empty_null) +export(iif_else) export(initialize_package) export(interpolate) +export(invert_named) export(is_valid_npi) export(is_valid_npi2) export(list_pins) export(make_interval) +export(max_vlen) export(mock_forager) export(mock_provider) export(mount_board) +export(na) +export(na_if) export(na_if_common) export(named_group_split) export(new_value) +export(not_na) +export(not_null) +export(null) export(pad_number) export(parens) export(percentage_calculator) @@ -68,16 +88,40 @@ export(percentage_change) export(percentage_difference) export(print_ls) export(random_npi_generator) +export(random_string) export(rate_of_return) +export(remove_all_na) export(remove_quiet) +export(remove_quotes) export(rename_seq) +export(roundup) export(search_for) +export(search_in) +export(sf_at) +export(sf_c) +export(sf_chars) +export(sf_conv) +export(sf_detect) +export(sf_extract) +export(sf_ndetect) +export(sf_nextract) +export(sf_remove) +export(sf_replace) +export(sf_smush) +export(sf_strsplit) +export(sf_sub) export(single_line_string) export(sorted_bars) export(splitter) +export(strsort) export(summary_stats) +export(true) export(ttimestamp) +export(uniq) +export(uniq_narm) +export(uniq_vlen) export(update_personal_packages) +export(vlen) export(years_df) export(years_floor) export(years_vec) diff --git a/R/describe.R b/R/describe.R index 788cd85..f30dbb3 100644 --- a/R/describe.R +++ b/R/describe.R @@ -1,3 +1,75 @@ +#' Describe 2 +#' +#' @param df `` desc +#' +#' @param ... `` tidyselect columns +#' +#' @returns `` of summary statistics +#' +#' @examples +#' describe2(mock_provider(2000:2020)) +#' +#' describe2(mock_forager(200)) +#' +#' @autoglobal +#' +#' @export +describe2 <- function(df, ...) { + + get_type <- \(x) { + cheapr::enframe_( + purrr::map_vec(x, function(x) + glue_chr("<{pillar::type_sum(x)}>")), + name = "column", + value = "type") + } + + fiqr <- \(x) diff(collapse::.quantile(as.numeric(x), c(0.25, 0.75))) + + if (nargs() > 1) df <- dplyr::select(df, ...) + + dates <- dplyr::select(df, dplyr::where(\(x) inherits(x, "Date"))) + df <- dplyr::select(df, dplyr::where(\(x) !inherits(x, "Date"))) + + sums <- df |> + dplyr::mutate( + dplyr::across(dplyr::where(is.character), stringr::str_length), + dplyr::across(dplyr::where(\(x) is.factor(x) | is.logical(x)), as.numeric)) |> + tidyr::pivot_longer(dplyr::everything(), names_to = "column") |> + dplyr::mutate(n = 1 - cheapr::is_na(value)) |> + dplyr::reframe( + n = collapse::fsum(value, nthreads = 4L), + min = collapse::fmin(value), + mean = collapse::fmean(value, nthreads = 4L), + iqr = fiqr(value), + max = collapse::fmax(value), + med = collapse::fmedian(value), + sd = collapse::fsd(value), + mad = mad(value, na.rm = TRUE), + distribution = histo(value), + .by = column) |> + dplyr::left_join(get_type(df), by = dplyr::join_by(column)) + + topn <- \(x, limit = 10) { + dplyr::tibble( + column = names(x), + uniq = collapse::fnunique(collapse::na_rm(x)), + top = collapse::fcount(collapse::na_rm(x), name = "n") |> + dplyr::arrange(dplyr::desc(n)) |> + dplyr::slice(seq(1, limit)) |> + dplyr::pull(x) |> + stringr::str_flatten_comma()) + } + + tops <- purrr::map(df, topn) |> + purrr::list_rbind(names_to = "column") |> + dplyr::filter(uniq != nrow(df)) + + dplyr::left_join(sums, tops, by = dplyr::join_by(column)) |> + dplyr::arrange(dplyr::desc(type)) |> + dplyr::select(column, type, n, min, mean, med, max, iqr, sd, mad, distribution, uniq, top) +} + #' Describe a dataset #' #' @param df `` desc @@ -140,9 +212,13 @@ histo <- function(x, width = 10) { #' #' @examples #' -#' describe_unique(mock_forager(), ins_class, payer) +#' describe_unique(mock_forager(), class, payer) #' -#' # describe_unique(mock_forager(200), names(df)[2:3]) +#' describe_unique( +#' mock_forager(50), +#' names(mock_forager())[c(2:3, 6:9)]) |> +#' dplyr::filter(n > 2) |> +#' print(n = 30) #' #' @autoglobal #' @@ -157,7 +233,9 @@ describe_unique <- function(df, df <- dplyr::select(df, ...) - .set_names <- if (is.null(.set_names)) names(df) else .set_names + .set_names <- if (null(.set_names)) names(df) else .set_names + + df <- dplyr::mutate(df, dplyr::across(!dplyr::where(is.character), as.character)) df <- columns_to_character(df) |> names() |> diff --git a/R/generated-globals.R b/R/generated-globals.R index bc9179c..1b3cc5d 100644 --- a/R/generated-globals.R +++ b/R/generated-globals.R @@ -9,6 +9,8 @@ utils::globalVariables(c( # # ":=", + # + "column", # "combined", # @@ -23,22 +25,28 @@ utils::globalVariables(c( "date_of_service", # "date_of_submission", + # + "distribution", # "group", # "group_size", # "interval", + # # "iqr", # "key", # "lg", + # # "mad", + # # "med", + # # # # @@ -46,12 +54,17 @@ utils::globalVariables(c( "n", # "nuniq", + # # "sd", + # + "top", # "top_n", + # # "type", + # # # "value", diff --git a/R/mock.R b/R/mock.R index 360d0ba..91d7f5c 100644 --- a/R/mock.R +++ b/R/mock.R @@ -29,7 +29,7 @@ mock_provider <- \(years) { #' #' @param rows `` number of rows to generate; default is 10 #' -#' @param nest `` whether to nest the dates column; default is `TRUE` +#' @param nest `` whether to nest the dates column; default is `FALSE` #' #' @returns A [tibble][tibble::tibble-package] #' @@ -41,23 +41,47 @@ mock_provider <- \(years) { #' @family mock #' #' @export -mock_forager <- function(rows = 10, nest = TRUE){ +mock_forager <- function(rows = 10, nest = FALSE){ - payer_names <- c("Medicare", "Medicaid", "Cigna", "Humana", "UHC", "Anthem", "BCBS", "Centene") + payers <- sample( + x = factor( + x = c("Medicare", + "Medicaid", + "Cigna", + "Humana", + "UHC", + "Anthem", + "BCBS", + "Centene", + "MAO")), + size = rows, + replace = TRUE) + + classes <- sample( + x = ordered( + c("Primary", + "Secondary")), + size = rows, + replace = TRUE) 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)))) + id = sprintf(paste0("%0", nchar(rows) + 3, "d"), seq_len(rows)), + payer = payers, + class = classes, + balance = roundup(stats::rgamma(n = rows, 2) * 20000) / 300, + date_of_service = sample(x = seq.Date(from = Sys.Date(), by = "-1 months", length.out = 12), size = rows, replace = TRUE), + date_of_release = date_of_service + roundup(abs(stats::rnorm(rows, 11, 4))), + date_of_submission = date_of_release + roundup(abs(stats::rnorm(rows, 2, 2))), + date_of_acceptance = date_of_submission + roundup(abs(stats::rnorm(rows, 3, 2))), + date_of_adjudication = date_of_acceptance + roundup(abs(stats::rnorm(rows, 30, 3))) + ) if (nest) - return(tidyr::nest(x, dates = tidyr::contains("date"))) - + return( + tidyr::nest( + x, + dates = tidyr::contains("date") + ) + ) x } diff --git a/R/standalone-helpers.R b/R/standalone-helpers.R index cc9111d..50341f9 100644 --- a/R/standalone-helpers.R +++ b/R/standalone-helpers.R @@ -52,14 +52,26 @@ #' #' @param x vector #' -#' @noRd +#' @returns `` `TRUE` if empty, else `FALSE` +#' +#' @keywords internal +#' +#' @autoglobal +#' +#' @export empty <- \(x) { vctrs::vec_is_empty(x) } #' If `x` is empty, `NULL`, else `x` #' #' @param x vector #' -#' @noRd +#' @returns `x` or `NULL` +#' +#' @keywords internal +#' +#' @autoglobal +#' +#' @export if_empty_null <- \(x) { if (empty(x)) NULL else x } #' Search in data frame @@ -81,7 +93,13 @@ search_in_impl <- \(x, column, what) vctrs::vec_slice(x, vctrs::vec_in(x[[column #' #' @param what to search for in `column` #' -#' @noRd +#' @returns vector or `` +#' +#' @keywords internal +#' +#' @autoglobal +#' +#' @export search_in <- \(x, column, what) { if (null(what)) return(x) @@ -97,7 +115,11 @@ search_in <- \(x, column, what) { #' #' @returns `x` with values in `y` converted to `NA` #' -#' @noRd +#' @keywords internal +#' +#' @autoglobal +#' +#' @export na_if <- \(x, y) { vctrs::vec_slice( @@ -120,14 +142,26 @@ na_if <- \(x, y) { #' @param yes,no Values to return depending on TRUE/FALSE element of `x`. Must #' be same type and be either length 1 or same length of `x`. #' -#' @noRd +#' @returns `` vector +#' +#' @keywords internal +#' +#' @autoglobal +#' +#' @export iif_else <- \(x, yes, no) { kit::iif(test = x, yes = yes, no = no, nThread = 4L) } #' Parallel Sort #' #' @param x `` vector. If other, will default to [base::sort()] #' -#' @noRd +#' @returns `` vector +#' +#' @keywords internal +#' +#' @autoglobal +#' +#' @export strsort <- \(x) { kit::psort(x, nThread = 4L) } # cheapr ------------------------------------------------------------------- @@ -136,21 +170,39 @@ strsort <- \(x) { kit::psort(x, nThread = 4L) } #' #' @param x vector #' -#' @noRd +#' @returns `` vector +#' +#' @keywords internal +#' +#' @autoglobal +#' +#' @export na <- \(x) { cheapr::is_na(x) } #' Predicate to filter out NAs #' #' @param x vector #' -#' @noRd +#' @returns `` vector +#' +#' @keywords internal +#' +#' @autoglobal +#' +#' @export not_na <- \(x) { !na(x) } #' Remove columns and rows with all NAs #' #' @param x vector or `` #' -#' @noRd +#' @returns vector or `` with columns and rows with all NAs removed +#' +#' @keywords internal +#' +#' @autoglobal +#' +#' @export remove_all_na <- \(x) { cheapr::na_rm(x[, !cheapr::col_all_na(x)]) } # collapse ----------------------------------------------------------------- @@ -161,7 +213,13 @@ remove_all_na <- \(x) { cheapr::na_rm(x[, !cheapr::col_all_na(x)]) } #' #' @param e `` element name; can be a regex pattern #' -#' @noRd +#' @returns `` element value +#' +#' @keywords internal +#' +#' @autoglobal +#' +#' @export getelem <- \(l, e) { collapse::get_elem(l = l, elem = e, regex = TRUE) } #' `getelem` with more flexibility @@ -174,7 +232,13 @@ getelem <- \(l, e) { collapse::get_elem(l = l, elem = e, regex = TRUE) } #' #' @param ... additional arguments to pass to `collapse::get_elem()` #' -#' @noRd +#' @returns `` or ``, depending on `m` +#' +#' @keywords internal +#' +#' @autoglobal +#' +#' @export gelm <- \(l, e, m = "re", ...) { collapse::get_elem( @@ -189,35 +253,65 @@ gelm <- \(l, e, m = "re", ...) { #' #' @param x vector #' -#' @noRd +#' @returns `` vector +#' +#' @keywords internal +#' +#' @autoglobal +#' +#' @export vlen <- \(x) { collapse::vlengths(x, use.names = FALSE) } #' Unique Values of Vector #' #' @param x vector #' -#' @noRd +#' @returns `` vector +#' +#' @keywords internal +#' +#' @autoglobal +#' +#' @export uniq <- \(x) { collapse::funique(x) } #' Unique Lengths of Vector #' #' @param x vector #' -#' @noRd +#' @returns `` vector +#' +#' @keywords internal +#' +#' @autoglobal +#' +#' @export uniq_vlen <- \(x) { uniq(vlen(x)) } #' Unique Values with NAs Removed #' #' @param x vector #' -#' @noRd +#' @returns `` vector +#' +#' @keywords internal +#' +#' @autoglobal +#' +#' @export uniq_narm <- \(x) { uniq(collapse::na_rm(x)) } #' Maximum Vector Length #' #' @param x vector #' -#' @noRd +#' @returns `` maximum length of vector +#' +#' @keywords internal +#' +#' @autoglobal +#' +#' @export max_vlen <- \(x) { collapse::fmax(vlen(x)) } # stringfish --------------------------------------------------------------- @@ -230,21 +324,39 @@ max_vlen <- \(x) { collapse::fmax(vlen(x)) } #' #' @param stop `` index end #' -#' @noRd +#' @returns `` vector +#' +#' @keywords internal +#' +#' @autoglobal +#' +#' @export sf_sub <- \(x, start = 1, stop) { stringfish::sf_substr(x, start = start, stop = stop, nthreads = 4L) } #' Convert string to stringfish vector #' #' @param x `` vector #' -#' @noRd +#' @returns `` vector +#' +#' @keywords internal +#' +#' @autoglobal +#' +#' @export sf_conv <- \(x) { stringfish::convert_to_sf(x) } #' Count number of characters in character vector #' #' @param x `` vector #' -#' @noRd +#' @returns `` vector +#' +#' @keywords internal +#' +#' @autoglobal +#' +#' @export sf_chars <- \(x) { stringfish::sf_nchar(x, nthreads = 4L) } #' Subset Vector at One Index Point @@ -253,7 +365,13 @@ sf_chars <- \(x) { stringfish::sf_nchar(x, nthreads = 4L) } #' #' @param idx `` index #' -#' @noRd +#' @returns `` vector +#' +#' @keywords internal +#' +#' @autoglobal +#' +#' @export sf_at <- \(x, idx = 1) { sf_sub(x, start = idx, stop = idx) } #' Detect by Regex @@ -262,7 +380,13 @@ sf_at <- \(x, idx = 1) { sf_sub(x, start = idx, stop = idx) } #' #' @param p `` regex pattern #' -#' @noRd +#' @returns `` vector +#' +#' @keywords internal +#' +#' @autoglobal +#' +#' @export sf_detect <- \(s, p) { stringfish::sf_grepl(s, p, nthreads = 4L) } #' Detect Opposite by Regex @@ -271,7 +395,13 @@ sf_detect <- \(s, p) { stringfish::sf_grepl(s, p, nthreads = 4L) } #' #' @param p `` regex pattern #' -#' @noRd +#' @returns `` vector +#' +#' @keywords internal +#' +#' @autoglobal +#' +#' @export sf_ndetect <- \(s, p) { !stringfish::sf_grepl(s, p, nthreads = 4L) } #' Extract by Regex @@ -280,7 +410,13 @@ sf_ndetect <- \(s, p) { !stringfish::sf_grepl(s, p, nthreads = 4L) } #' #' @param p `` regex pattern #' -#' @noRd +#' @returns `` vector with pattern extracted +#' +#' @keywords internal +#' +#' @autoglobal +#' +#' @export sf_extract <- \(s, p) { s[sf_detect(s, p)] } #' Extract Opposite by Regex @@ -289,7 +425,13 @@ sf_extract <- \(s, p) { s[sf_detect(s, p)] } #' #' @param p `` regex pattern #' -#' @noRd +#' @returns `` vector with pattern extracted +#' +#' @keywords internal +#' +#' @autoglobal +#' +#' @export sf_nextract <- \(s, p) { s[sf_ndetect(s, p)] } #' Replace by Regex @@ -302,7 +444,13 @@ sf_nextract <- \(s, p) { s[sf_ndetect(s, p)] } #' #' @param fix `` fixed or regex; default is `FALSE` #' -#' @noRd +#' @returns `` vector with pattern replaced +#' +#' @keywords internal +#' +#' @autoglobal +#' +#' @export sf_replace <- \(s, p, r, fix = FALSE) { stringfish::sf_gsub(subject = s, pattern = p, replacement = r, fixed = fix, nthreads = 4L) } #' Remove by Regex @@ -313,21 +461,39 @@ sf_replace <- \(s, p, r, fix = FALSE) { stringfish::sf_gsub(subject = s, pattern #' #' @param fix `` fixed or regex; default is `FALSE` #' -#' @noRd +#' @returns `` vector with pattern removed +#' +#' @keywords internal +#' +#' @autoglobal +#' +#' @export sf_remove <- \(s, p, fix = FALSE) { stringfish::sf_gsub(subject = s, pattern = p, replacement = "", fixed = fix, nthreads = 4L) } #' Remove single or double quotes from a character string #' #' @param x `` vector to convert #' -#' @noRd -remove_quotes <- \(x) { sf_remove(x, '["\']') } +#' @returns `` vector with quotes removed +#' +#' @keywords internal +#' +#' @autoglobal +#' +#' @export +remove_quotes <- \(x) { if (is.character(x)) sf_remove(x, '["\']') else x } #' Concatenate Vectors #' #' @param ... Any number of vectors, coerced to `` vector, if necessary #' -#' @noRd +#' @returns `` concatenated vector +#' +#' @keywords internal +#' +#' @autoglobal +#' +#' @export sf_c <- \(...) { stringfish::sfc(...) } #' Collapse Vector @@ -336,7 +502,13 @@ sf_c <- \(...) { stringfish::sfc(...) } #' #' @param sep `` separator; default is `""` #' -#' @noRd +#' @returns `` collapsed vector +#' +#' @keywords internal +#' +#' @autoglobal +#' +#' @export sf_smush <- \(x, sep = "") { stringfish::sf_collapse(x, collapse = sep) } #' Split string by delimiter @@ -347,7 +519,13 @@ sf_smush <- \(x, sep = "") { stringfish::sf_collapse(x, collapse = sep) } #' #' @param fix `` fixed or regex; default is `TRUE` #' -#' @noRd +#' @returns `` of split strings +#' +#' @keywords internal +#' +#' @autoglobal +#' +#' @export sf_strsplit <- \(x, s, fix = TRUE) { stringfish::sf_split(subject = x, split = s, fixed = fix, nthreads = 4L) } # stringi ----------------------------------------------------------------- @@ -360,7 +538,13 @@ sf_strsplit <- \(x, s, fix = TRUE) { stringfish::sf_split(subject = x, split = s #' #' @param p `` pattern to sample from; default is `"[A-Z0-9]"` #' -#' @noRd +#' @returns `` vector of random strings +#' +#' @keywords internal +#' +#' @autoglobal +#' +#' @export random_string <- \(n, ln, p = "[A-Z0-9]") { stringi::stri_rand_strings(n = n, length = ln, pattern = p) } # base -------------------------------------------------------------------- @@ -371,14 +555,22 @@ random_string <- \(n, ln, p = "[A-Z0-9]") { stringi::stri_rand_strings(n = n, le #' #' @returns Unnamed `` vector #' -#' @noRd +#' @keywords internal +#' +#' @autoglobal +#' +#' @export delist <- \(x) { unlist(x, use.names = FALSE) } #' Unlist, unname and split #' #' @param x `` string or named `` #' -#' @noRd +#' @keywords internal +#' +#' @autoglobal +#' +#' @export desplit <- \(x) { res <- sf_strsplit(delist(x), "") @@ -394,7 +586,11 @@ desplit <- \(x) { #' #' @returns `` `TRUE` if `x` is `NULL`, else `FALSE` #' -#' @noRd +#' @keywords internal +#' +#' @autoglobal +#' +#' @export null <- \(x) { is.null(x) } #' Is `x` not `NULL`? @@ -403,7 +599,11 @@ null <- \(x) { is.null(x) } #' #' @returns `` `TRUE` if `x` is not `NULL`, else `FALSE` #' -#' @noRd +#' @keywords internal +#' +#' @autoglobal +#' +#' @export not_null <- \(x) { !null(x) } #' Is `x` `TRUE`? @@ -412,7 +612,11 @@ not_null <- \(x) { !null(x) } #' #' @returns `` `TRUE` if `x` is `TRUE`, else `FALSE` #' -#' @noRd +#' @keywords internal +#' +#' @autoglobal +#' +#' @export true <- \(x) { isTRUE(x) } #' Is `x` `FALSE`? @@ -421,7 +625,11 @@ true <- \(x) { isTRUE(x) } #' #' @returns `` `TRUE` if `x` is `FALSE`, else `FALSE` #' -#' @noRd +#' @keywords internal +#' +#' @autoglobal +#' +#' @export false <- \(x) { isFALSE(x) } #' Coerce vector to `` @@ -430,9 +638,11 @@ false <- \(x) { isFALSE(x) } #' #' @returns `` vector #' +#' @keywords internal +#' #' @autoglobal #' -#' @noRd +#' @export as_chr <- \(x) { if (is.character(x)) x else as.character(x) } #' Coerce vector to `` @@ -441,9 +651,11 @@ as_chr <- \(x) { if (is.character(x)) x else as.character(x) } #' #' @returns `` vector #' +#' @keywords internal +#' #' @autoglobal #' -#' @noRd +#' @export as_int <- \(x) { if (is.integer(x)) x else as.integer(x) } #' Coerce vector to `` class @@ -452,9 +664,11 @@ as_int <- \(x) { if (is.integer(x)) x else as.integer(x) } #' #' @returns `` vector #' +#' @keywords internal +#' #' @autoglobal #' -#' @noRd +#' @export as_num <- \(x) { if (is.numeric(x)) x else as.numeric(x) } #' Coerce vector to `` class @@ -467,9 +681,11 @@ as_num <- \(x) { if (is.numeric(x)) x else as.numeric(x) } #' #' @returns `` vector #' +#' @keywords internal +#' #' @autoglobal #' -#' @noRd +#' @export as_date <- \(x, ..., fmt = "%Y-%m-%d") { as.Date(x, ..., format = fmt) } #' Invert a named vector @@ -478,9 +694,11 @@ as_date <- \(x, ..., fmt = "%Y-%m-%d") { as.Date(x, ..., format = fmt) } #' #' @returns A named vector with names and values inverted #' +#' @keywords internal +#' #' @autoglobal #' -#' @noRd +#' @export invert_named <- \(x) { stopifnot("Input must be a named vector" = not_null(names(x))) @@ -496,9 +714,11 @@ invert_named <- \(x) { #' #' @returns `` vector rounded up to the nearest decimal place #' +#' @keywords internal +#' #' @autoglobal #' -#' @noRd +#' @export roundup <- \(x, d = 2) { d <- 10^d diff --git a/R/tidyverse.R b/R/tidyverse.R index af581ca..528f94e 100644 --- a/R/tidyverse.R +++ b/R/tidyverse.R @@ -250,16 +250,11 @@ display_long <- function(data) { #' @returns A `` with combined columns #' #' @examples -#' x <- mock_forager()[-5] +#' x <- mock_forager() #' -#' x[1, 2] <- "" +#' x[1, 1] <- "" #' -#' x -#' -#' combine( -#' data = x, -#' name = payer, -#' columns = c('claim_id', 'payer')) +#' combine(x, payer, c("payer", "id")) #' #' @autoglobal #' @@ -322,7 +317,7 @@ count_prop <- function(df, var, sort = FALSE, na.rm = FALSE) { #' @examples #' mock_forager(10) |> #' count_prop_multi( -#' c(ins_class), +#' c(class), #' payer, #' sort = TRUE) #' @@ -345,7 +340,7 @@ count_prop_multi <- function(df, rows, cols, sort = FALSE, na.rm = FALSE) { #' #' @examples #' mock_forager(10) |> -#' count_wide(c(ins_class), payer) +#' count_wide(c(class), payer) #' #' @autoglobal #' diff --git a/data-raw/dev/codebook.R b/data-raw/dev/codebook.R new file mode 100644 index 0000000..5433b2f --- /dev/null +++ b/data-raw/dev/codebook.R @@ -0,0 +1,118 @@ +# Codebook + +## Code + +```{r} +#| label: code +code <- \(variable, levels, labels) { + dplyr::tibble( + variable = variable, + level = levels, + label = labels) +} + +code( + "SEX", + levels = c(0, 1), + labels = c("Male", "Female")) +``` + +## Codebook + +```{r} +#| label: codebook +codebook <- \(...) { + + map <- rlang::list2(...) + + names(map) <- purrr::map_chr(map, \(x) x$variable[1]) + + return(map) +} + +codebook( + code("SEX", + levels = 0:1, + labels = c("Male", "Female")), + code("STUDY", + levels = 1:3, + labels = c("S1", "S2", "S3"))) +``` + +## Encode + +```{r} +#| label: encode +encode <- \(data, codebook) { + + mapped_vars <- names(codebook) + + mapped_data <- purrr::map2(data, names(data), \(x, var, m) { + + if (!var %in% mapped_vars) return(x) + + x <- factor(x, levels = m[[var]]$level, labels = m[[var]]$label) + + return(x) + }, + m <- codebook + ) + dplyr::as_tibble(mapped_data) +} + +labels <- codebook( + code("SEX", + levels = 0:1, + labels = c("Male", "Female")), + code("STUDY", + levels = 1:3, + labels = c("S1", "S2", "S3")) +) + +dataset <- data.frame( + STUDY = c(1, 1, 1, 2, 2, 2), + SEX = c(0, 0, 1, 1, 1, 0), + AGE = c(32, 18, 64, 52, 26, 80) +) + +encode(dataset, labels) +``` + +## Decode + +```{r} +#| label: decode +decode <- \(data, codebook) { + + mapped_vars <- names(codebook) + + mapped_data <- purrr::map2(data, names(data), \(x, var, m) { + + if (!var %in% mapped_vars) return(x) + + x_chr <- as.character(x) + + x_lvl <- m[[var]]$level + + x_lab <- m[[var]]$label + + x <- x_lvl[match(x_chr, x_lab)] + + return(x) + }, + m <- codebook + ) + dplyr::as_tibble(mapped_data) +} + +labels <- codebook( + code("SEX", levels = c(0, 1), labels = c("Male", "Female")), + code("STUDY", levels = c(1, 2, 3), labels = c("S1", "S2", "S3"))) + +dataset <- data.frame( + STUDY = factor(c("S1", "S1", "S1", "S2", "S2", "S2")), + SEX = factor(c("Male", "Male", "Female", "Female", "Female", "Male")), + AGE = c(32, 18, 64, 52, 26, 80)) + +decode(dataset, labels) +``` diff --git a/fuimus.Rproj b/fuimus.Rproj index 69fafd4..2efad50 100644 --- a/fuimus.Rproj +++ b/fuimus.Rproj @@ -1,4 +1,5 @@ Version: 1.0 +ProjectId: 5be78d81-c5e9-4881-9ae9-d021252d1569 RestoreWorkspace: No SaveWorkspace: No diff --git a/man/as_chr.Rd b/man/as_chr.Rd new file mode 100644 index 0000000..20b98a4 --- /dev/null +++ b/man/as_chr.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standalone-helpers.R +\name{as_chr} +\alias{as_chr} +\title{Coerce vector to \verb{}} +\usage{ +as_chr(x) +} +\arguments{ +\item{x}{vector} +} +\value{ +\verb{} vector +} +\description{ +Coerce vector to \verb{} +} +\keyword{internal} diff --git a/man/as_date.Rd b/man/as_date.Rd new file mode 100644 index 0000000..ebfc9c3 --- /dev/null +++ b/man/as_date.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standalone-helpers.R +\name{as_date} +\alias{as_date} +\title{Coerce vector to \verb{} class} +\usage{ +as_date(x, ..., fmt = "\%Y-\%m-\%d") +} +\arguments{ +\item{x}{vector} + +\item{...}{additional arguments} + +\item{fmt}{\verb{} format; default is \code{"\%Y-\%m-\%d"}} +} +\value{ +\verb{} vector +} +\description{ +Coerce vector to \verb{} class +} +\keyword{internal} diff --git a/man/as_int.Rd b/man/as_int.Rd new file mode 100644 index 0000000..0a45640 --- /dev/null +++ b/man/as_int.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standalone-helpers.R +\name{as_int} +\alias{as_int} +\title{Coerce vector to \verb{}} +\usage{ +as_int(x) +} +\arguments{ +\item{x}{vector} +} +\value{ +\verb{} vector +} +\description{ +Coerce vector to \verb{} +} +\keyword{internal} diff --git a/man/as_num.Rd b/man/as_num.Rd new file mode 100644 index 0000000..d1252c7 --- /dev/null +++ b/man/as_num.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standalone-helpers.R +\name{as_num} +\alias{as_num} +\title{Coerce vector to \verb{} class} +\usage{ +as_num(x) +} +\arguments{ +\item{x}{vector} +} +\value{ +\verb{} vector +} +\description{ +Coerce vector to \verb{} class +} +\keyword{internal} diff --git a/man/combine.Rd b/man/combine.Rd index 922c09f..f9f9ba3 100644 --- a/man/combine.Rd +++ b/man/combine.Rd @@ -22,15 +22,10 @@ A \verb{} with combined columns Combine multiple columns into one } \examples{ -x <- mock_forager()[-5] +x <- mock_forager() -x[1, 2] <- "" +x[1, 1] <- "" -x - -combine( - data = x, - name = payer, - columns = c('claim_id', 'payer')) +combine(x, payer, c("payer", "id")) } diff --git a/man/count_prop_multi.Rd b/man/count_prop_multi.Rd index 2b602e7..21fcd4e 100644 --- a/man/count_prop_multi.Rd +++ b/man/count_prop_multi.Rd @@ -25,7 +25,7 @@ Count and calculate proportion of each group \examples{ mock_forager(10) |> count_prop_multi( - c(ins_class), + c(class), payer, sort = TRUE) diff --git a/man/count_wide.Rd b/man/count_wide.Rd index 552eabf..efbf2f7 100644 --- a/man/count_wide.Rd +++ b/man/count_wide.Rd @@ -18,6 +18,6 @@ Count rows and columns and pivot to wide format } \examples{ mock_forager(10) |> - count_wide(c(ins_class), payer) + count_wide(c(class), payer) } diff --git a/man/delist.Rd b/man/delist.Rd new file mode 100644 index 0000000..751ae14 --- /dev/null +++ b/man/delist.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standalone-helpers.R +\name{delist} +\alias{delist} +\title{Unlist and unname} +\usage{ +delist(x) +} +\arguments{ +\item{x}{Named or unnamed \verb{}} +} +\value{ +Unnamed \verb{} vector +} +\description{ +Unlist and unname +} +\keyword{internal} diff --git a/man/describe2.Rd b/man/describe2.Rd new file mode 100644 index 0000000..a00d276 --- /dev/null +++ b/man/describe2.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/describe.R +\name{describe2} +\alias{describe2} +\title{Describe 2} +\usage{ +describe2(df, ...) +} +\arguments{ +\item{df}{\verb{} desc} + +\item{...}{\verb{} tidyselect columns} +} +\value{ +\verb{} of summary statistics +} +\description{ +Describe 2 +} +\examples{ +describe2(mock_provider(2000:2020)) + +describe2(mock_forager(200)) + +} diff --git a/man/describe_unique.Rd b/man/describe_unique.Rd index b5f6b71..4d53f3b 100644 --- a/man/describe_unique.Rd +++ b/man/describe_unique.Rd @@ -31,8 +31,12 @@ Describe unique values in a data frame } \examples{ -describe_unique(mock_forager(), ins_class, payer) +describe_unique(mock_forager(), class, payer) -# describe_unique(mock_forager(200), names(df)[2:3]) +describe_unique( + mock_forager(50), + names(mock_forager())[c(2:3, 6:9)]) |> + dplyr::filter(n > 2) |> + print(n = 30) } diff --git a/man/desplit.Rd b/man/desplit.Rd new file mode 100644 index 0000000..4162fa4 --- /dev/null +++ b/man/desplit.Rd @@ -0,0 +1,15 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standalone-helpers.R +\name{desplit} +\alias{desplit} +\title{Unlist, unname and split} +\usage{ +desplit(x) +} +\arguments{ +\item{x}{\verb{} string or named \verb{}} +} +\description{ +Unlist, unname and split +} +\keyword{internal} diff --git a/man/empty.Rd b/man/empty.Rd new file mode 100644 index 0000000..d3ea45a --- /dev/null +++ b/man/empty.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standalone-helpers.R +\name{empty} +\alias{empty} +\title{Is Vector Empty?} +\usage{ +empty(x) +} +\arguments{ +\item{x}{vector} +} +\value{ +\verb{} \code{TRUE} if empty, else \code{FALSE} +} +\description{ +Is Vector Empty? +} +\keyword{internal} diff --git a/man/false.Rd b/man/false.Rd new file mode 100644 index 0000000..c2d961d --- /dev/null +++ b/man/false.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standalone-helpers.R +\name{false} +\alias{false} +\title{Is \code{x} \code{FALSE}?} +\usage{ +false(x) +} +\arguments{ +\item{x}{input} +} +\value{ +\verb{} \code{TRUE} if \code{x} is \code{FALSE}, else \code{FALSE} +} +\description{ +Is \code{x} \code{FALSE}? +} +\keyword{internal} diff --git a/man/gelm.Rd b/man/gelm.Rd new file mode 100644 index 0000000..4a34f5c --- /dev/null +++ b/man/gelm.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standalone-helpers.R +\name{gelm} +\alias{gelm} +\title{\code{getelem} with more flexibility} +\usage{ +gelm(l, e, m = "re", ...) +} +\arguments{ +\item{l}{named \verb{}} + +\item{e}{\verb{} element name; can be a regex pattern if \code{m} is \code{"re"}} + +\item{m}{\verb{} mode; default is \code{"re"} (regex) or \code{"df"} (data frame)} + +\item{...}{additional arguments to pass to \code{collapse::get_elem()}} +} +\value{ +\verb{} or \verb{}, depending on \code{m} +} +\description{ +\code{getelem} with more flexibility +} +\keyword{internal} diff --git a/man/getelem.Rd b/man/getelem.Rd new file mode 100644 index 0000000..f8a091d --- /dev/null +++ b/man/getelem.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standalone-helpers.R +\name{getelem} +\alias{getelem} +\title{Get named element from list} +\usage{ +getelem(l, e) +} +\arguments{ +\item{l}{named \verb{}} + +\item{e}{\verb{} element name; can be a regex pattern} +} +\value{ +\verb{} element value +} +\description{ +Get named element from list +} +\keyword{internal} diff --git a/man/if_empty_null.Rd b/man/if_empty_null.Rd new file mode 100644 index 0000000..890d61b --- /dev/null +++ b/man/if_empty_null.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standalone-helpers.R +\name{if_empty_null} +\alias{if_empty_null} +\title{If \code{x} is empty, \code{NULL}, else \code{x}} +\usage{ +if_empty_null(x) +} +\arguments{ +\item{x}{vector} +} +\value{ +\code{x} or \code{NULL} +} +\description{ +If \code{x} is empty, \code{NULL}, else \code{x} +} +\keyword{internal} diff --git a/man/iif_else.Rd b/man/iif_else.Rd new file mode 100644 index 0000000..ad69e2f --- /dev/null +++ b/man/iif_else.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standalone-helpers.R +\name{iif_else} +\alias{iif_else} +\title{ifelse wrapper using kit::iif} +\usage{ +iif_else(x, yes, no) +} +\arguments{ +\item{x}{\verb{} vector} + +\item{yes, no}{Values to return depending on TRUE/FALSE element of \code{x}. Must +be same type and be either length 1 or same length of \code{x}.} +} +\value{ +\verb{} vector +} +\description{ +ifelse wrapper using kit::iif +} +\keyword{internal} diff --git a/man/invert_named.Rd b/man/invert_named.Rd new file mode 100644 index 0000000..50962ac --- /dev/null +++ b/man/invert_named.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standalone-helpers.R +\name{invert_named} +\alias{invert_named} +\title{Invert a named vector} +\usage{ +invert_named(x) +} +\arguments{ +\item{x}{A named vector} +} +\value{ +A named vector with names and values inverted +} +\description{ +Invert a named vector +} +\keyword{internal} diff --git a/man/max_vlen.Rd b/man/max_vlen.Rd new file mode 100644 index 0000000..f5e74e7 --- /dev/null +++ b/man/max_vlen.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standalone-helpers.R +\name{max_vlen} +\alias{max_vlen} +\title{Maximum Vector Length} +\usage{ +max_vlen(x) +} +\arguments{ +\item{x}{vector} +} +\value{ +\verb{} maximum length of vector +} +\description{ +Maximum Vector Length +} +\keyword{internal} diff --git a/man/mock_forager.Rd b/man/mock_forager.Rd index 3844ed3..1de2c57 100644 --- a/man/mock_forager.Rd +++ b/man/mock_forager.Rd @@ -4,12 +4,12 @@ \alias{mock_forager} \title{Generate mock coding/billing data frame} \usage{ -mock_forager(rows = 10, nest = TRUE) +mock_forager(rows = 10, nest = FALSE) } \arguments{ \item{rows}{\verb{} number of rows to generate; default is 10} -\item{nest}{\verb{} whether to nest the dates column; default is \code{TRUE}} +\item{nest}{\verb{} whether to nest the dates column; default is \code{FALSE}} } \value{ A \link[tibble:tibble-package]{tibble} diff --git a/man/na.Rd b/man/na.Rd new file mode 100644 index 0000000..b26d548 --- /dev/null +++ b/man/na.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standalone-helpers.R +\name{na} +\alias{na} +\title{Predicate to filter out NAs} +\usage{ +na(x) +} +\arguments{ +\item{x}{vector} +} +\value{ +\verb{} vector +} +\description{ +Predicate to filter out NAs +} +\keyword{internal} diff --git a/man/na_if.Rd b/man/na_if.Rd new file mode 100644 index 0000000..46253cb --- /dev/null +++ b/man/na_if.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standalone-helpers.R +\name{na_if} +\alias{na_if} +\title{Convert values to \code{NA}} +\usage{ +na_if(x, y) +} +\arguments{ +\item{x}{vector to modify} + +\item{y}{values to convert to \code{NA}. Type must match that of \code{x}.} +} +\value{ +\code{x} with values in \code{y} converted to \code{NA} +} +\description{ +Convert values to \code{NA} +} +\keyword{internal} diff --git a/man/not_na.Rd b/man/not_na.Rd new file mode 100644 index 0000000..8ddcf32 --- /dev/null +++ b/man/not_na.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standalone-helpers.R +\name{not_na} +\alias{not_na} +\title{Predicate to filter out NAs} +\usage{ +not_na(x) +} +\arguments{ +\item{x}{vector} +} +\value{ +\verb{} vector +} +\description{ +Predicate to filter out NAs +} +\keyword{internal} diff --git a/man/not_null.Rd b/man/not_null.Rd new file mode 100644 index 0000000..8507870 --- /dev/null +++ b/man/not_null.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standalone-helpers.R +\name{not_null} +\alias{not_null} +\title{Is \code{x} not \code{NULL}?} +\usage{ +not_null(x) +} +\arguments{ +\item{x}{input} +} +\value{ +\verb{} \code{TRUE} if \code{x} is not \code{NULL}, else \code{FALSE} +} +\description{ +Is \code{x} not \code{NULL}? +} +\keyword{internal} diff --git a/man/null.Rd b/man/null.Rd new file mode 100644 index 0000000..b7c1ce1 --- /dev/null +++ b/man/null.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standalone-helpers.R +\name{null} +\alias{null} +\title{Is \code{x} \code{NULL}?} +\usage{ +null(x) +} +\arguments{ +\item{x}{input} +} +\value{ +\verb{} \code{TRUE} if \code{x} is \code{NULL}, else \code{FALSE} +} +\description{ +Is \code{x} \code{NULL}? +} +\keyword{internal} diff --git a/man/random_string.Rd b/man/random_string.Rd new file mode 100644 index 0000000..faffd21 --- /dev/null +++ b/man/random_string.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standalone-helpers.R +\name{random_string} +\alias{random_string} +\title{Generate random strings} +\usage{ +random_string(n, ln, p = "[A-Z0-9]") +} +\arguments{ +\item{n}{\verb{} number of strings to generate} + +\item{ln}{\verb{} length of each string} + +\item{p}{\verb{} pattern to sample from; default is \code{"[A-Z0-9]"}} +} +\value{ +\verb{} vector of random strings +} +\description{ +Generate random strings +} +\keyword{internal} diff --git a/man/remove_all_na.Rd b/man/remove_all_na.Rd new file mode 100644 index 0000000..8e856c1 --- /dev/null +++ b/man/remove_all_na.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standalone-helpers.R +\name{remove_all_na} +\alias{remove_all_na} +\title{Remove columns and rows with all NAs} +\usage{ +remove_all_na(x) +} +\arguments{ +\item{x}{vector or \verb{}} +} +\value{ +vector or \verb{} with columns and rows with all NAs removed +} +\description{ +Remove columns and rows with all NAs +} +\keyword{internal} diff --git a/man/remove_quotes.Rd b/man/remove_quotes.Rd new file mode 100644 index 0000000..27ceec7 --- /dev/null +++ b/man/remove_quotes.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standalone-helpers.R +\name{remove_quotes} +\alias{remove_quotes} +\title{Remove single or double quotes from a character string} +\usage{ +remove_quotes(x) +} +\arguments{ +\item{x}{\verb{} vector to convert} +} +\value{ +\verb{} vector with quotes removed +} +\description{ +Remove single or double quotes from a character string +} +\keyword{internal} diff --git a/man/roundup.Rd b/man/roundup.Rd new file mode 100644 index 0000000..53fc4e9 --- /dev/null +++ b/man/roundup.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standalone-helpers.R +\name{roundup} +\alias{roundup} +\title{Round up to nearest decimal place} +\usage{ +roundup(x, d = 2) +} +\arguments{ +\item{x}{\verb{} vector} + +\item{d}{\verb{} decimal places to round to; default is \code{2}} +} +\value{ +\verb{} vector rounded up to the nearest decimal place +} +\description{ +Round up to nearest decimal place +} +\keyword{internal} diff --git a/man/search_in.Rd b/man/search_in.Rd new file mode 100644 index 0000000..250ad2f --- /dev/null +++ b/man/search_in.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standalone-helpers.R +\name{search_in} +\alias{search_in} +\title{Search in data frame column if search term is not \code{NULL}} +\usage{ +search_in(x, column, what) +} +\arguments{ +\item{x}{vector or \verb{}} + +\item{column}{\verb{} string of column name} + +\item{what}{to search for in \code{column}} +} +\value{ +vector or \verb{} +} +\description{ +Search in data frame column if search term is not \code{NULL} +} +\keyword{internal} diff --git a/man/sf_at.Rd b/man/sf_at.Rd new file mode 100644 index 0000000..244b08b --- /dev/null +++ b/man/sf_at.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standalone-helpers.R +\name{sf_at} +\alias{sf_at} +\title{Subset Vector at One Index Point} +\usage{ +sf_at(x, idx = 1) +} +\arguments{ +\item{x}{\verb{} vector} + +\item{idx}{\verb{} index} +} +\value{ +\verb{} vector +} +\description{ +Subset Vector at One Index Point +} +\keyword{internal} diff --git a/man/sf_c.Rd b/man/sf_c.Rd new file mode 100644 index 0000000..3252230 --- /dev/null +++ b/man/sf_c.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standalone-helpers.R +\name{sf_c} +\alias{sf_c} +\title{Concatenate Vectors} +\usage{ +sf_c(...) +} +\arguments{ +\item{...}{Any number of vectors, coerced to \verb{} vector, if necessary} +} +\value{ +\verb{} concatenated vector +} +\description{ +Concatenate Vectors +} +\keyword{internal} diff --git a/man/sf_chars.Rd b/man/sf_chars.Rd new file mode 100644 index 0000000..f9ff467 --- /dev/null +++ b/man/sf_chars.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standalone-helpers.R +\name{sf_chars} +\alias{sf_chars} +\title{Count number of characters in character vector} +\usage{ +sf_chars(x) +} +\arguments{ +\item{x}{\verb{} vector} +} +\value{ +\verb{} vector +} +\description{ +Count number of characters in character vector +} +\keyword{internal} diff --git a/man/sf_conv.Rd b/man/sf_conv.Rd new file mode 100644 index 0000000..26ab065 --- /dev/null +++ b/man/sf_conv.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standalone-helpers.R +\name{sf_conv} +\alias{sf_conv} +\title{Convert string to stringfish vector} +\usage{ +sf_conv(x) +} +\arguments{ +\item{x}{\verb{} vector} +} +\value{ +\verb{} vector +} +\description{ +Convert string to stringfish vector +} +\keyword{internal} diff --git a/man/sf_detect.Rd b/man/sf_detect.Rd new file mode 100644 index 0000000..793c312 --- /dev/null +++ b/man/sf_detect.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standalone-helpers.R +\name{sf_detect} +\alias{sf_detect} +\title{Detect by Regex} +\usage{ +sf_detect(s, p) +} +\arguments{ +\item{s}{\verb{} vector} + +\item{p}{\verb{} regex pattern} +} +\value{ +\verb{} vector +} +\description{ +Detect by Regex +} +\keyword{internal} diff --git a/man/sf_extract.Rd b/man/sf_extract.Rd new file mode 100644 index 0000000..ba3770a --- /dev/null +++ b/man/sf_extract.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standalone-helpers.R +\name{sf_extract} +\alias{sf_extract} +\title{Extract by Regex} +\usage{ +sf_extract(s, p) +} +\arguments{ +\item{s}{\verb{} vector} + +\item{p}{\verb{} regex pattern} +} +\value{ +\verb{} vector with pattern extracted +} +\description{ +Extract by Regex +} +\keyword{internal} diff --git a/man/sf_ndetect.Rd b/man/sf_ndetect.Rd new file mode 100644 index 0000000..c471dfe --- /dev/null +++ b/man/sf_ndetect.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standalone-helpers.R +\name{sf_ndetect} +\alias{sf_ndetect} +\title{Detect Opposite by Regex} +\usage{ +sf_ndetect(s, p) +} +\arguments{ +\item{s}{\verb{} vector} + +\item{p}{\verb{} regex pattern} +} +\value{ +\verb{} vector +} +\description{ +Detect Opposite by Regex +} +\keyword{internal} diff --git a/man/sf_nextract.Rd b/man/sf_nextract.Rd new file mode 100644 index 0000000..b6010dc --- /dev/null +++ b/man/sf_nextract.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standalone-helpers.R +\name{sf_nextract} +\alias{sf_nextract} +\title{Extract Opposite by Regex} +\usage{ +sf_nextract(s, p) +} +\arguments{ +\item{s}{\verb{} vector} + +\item{p}{\verb{} regex pattern} +} +\value{ +\verb{} vector with pattern extracted +} +\description{ +Extract Opposite by Regex +} +\keyword{internal} diff --git a/man/sf_remove.Rd b/man/sf_remove.Rd new file mode 100644 index 0000000..ba34ccd --- /dev/null +++ b/man/sf_remove.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standalone-helpers.R +\name{sf_remove} +\alias{sf_remove} +\title{Remove by Regex} +\usage{ +sf_remove(s, p, fix = FALSE) +} +\arguments{ +\item{s}{\verb{} vector} + +\item{p}{\verb{} regex pattern} + +\item{fix}{\verb{} fixed or regex; default is \code{FALSE}} +} +\value{ +\verb{} vector with pattern removed +} +\description{ +Remove by Regex +} +\keyword{internal} diff --git a/man/sf_replace.Rd b/man/sf_replace.Rd new file mode 100644 index 0000000..dbe277b --- /dev/null +++ b/man/sf_replace.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standalone-helpers.R +\name{sf_replace} +\alias{sf_replace} +\title{Replace by Regex} +\usage{ +sf_replace(s, p, r, fix = FALSE) +} +\arguments{ +\item{s}{\verb{} vector} + +\item{p}{\verb{} regex pattern} + +\item{r}{\verb{} replacement} + +\item{fix}{\verb{} fixed or regex; default is \code{FALSE}} +} +\value{ +\verb{} vector with pattern replaced +} +\description{ +Replace by Regex +} +\keyword{internal} diff --git a/man/sf_smush.Rd b/man/sf_smush.Rd new file mode 100644 index 0000000..bb1b950 --- /dev/null +++ b/man/sf_smush.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standalone-helpers.R +\name{sf_smush} +\alias{sf_smush} +\title{Collapse Vector} +\usage{ +sf_smush(x, sep = "") +} +\arguments{ +\item{x}{\verb{} vector} + +\item{sep}{\verb{} separator; default is \code{""}} +} +\value{ +\verb{} collapsed vector +} +\description{ +Collapse Vector +} +\keyword{internal} diff --git a/man/sf_strsplit.Rd b/man/sf_strsplit.Rd new file mode 100644 index 0000000..f8c799c --- /dev/null +++ b/man/sf_strsplit.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standalone-helpers.R +\name{sf_strsplit} +\alias{sf_strsplit} +\title{Split string by delimiter} +\usage{ +sf_strsplit(x, s, fix = TRUE) +} +\arguments{ +\item{x}{\verb{} vector} + +\item{s}{\verb{} delimiter to split by} + +\item{fix}{\verb{} fixed or regex; default is \code{TRUE}} +} +\value{ +\verb{} of split strings +} +\description{ +Split string by delimiter +} +\keyword{internal} diff --git a/man/sf_sub.Rd b/man/sf_sub.Rd new file mode 100644 index 0000000..ec36613 --- /dev/null +++ b/man/sf_sub.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standalone-helpers.R +\name{sf_sub} +\alias{sf_sub} +\title{Subset Vector by Range} +\usage{ +sf_sub(x, start = 1, stop) +} +\arguments{ +\item{x}{\verb{} vector} + +\item{start}{\verb{} index start; default is \code{1}} + +\item{stop}{\verb{} index end} +} +\value{ +\verb{} vector +} +\description{ +Subset Vector by Range +} +\keyword{internal} diff --git a/man/strsort.Rd b/man/strsort.Rd new file mode 100644 index 0000000..2335ab1 --- /dev/null +++ b/man/strsort.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standalone-helpers.R +\name{strsort} +\alias{strsort} +\title{Parallel Sort} +\usage{ +strsort(x) +} +\arguments{ +\item{x}{\verb{} vector. If other, will default to \code{\link[base:sort]{base::sort()}}} +} +\value{ +\verb{} vector +} +\description{ +Parallel Sort +} +\keyword{internal} diff --git a/man/true.Rd b/man/true.Rd new file mode 100644 index 0000000..3a4a78b --- /dev/null +++ b/man/true.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standalone-helpers.R +\name{true} +\alias{true} +\title{Is \code{x} \code{TRUE}?} +\usage{ +true(x) +} +\arguments{ +\item{x}{input} +} +\value{ +\verb{} \code{TRUE} if \code{x} is \code{TRUE}, else \code{FALSE} +} +\description{ +Is \code{x} \code{TRUE}? +} +\keyword{internal} diff --git a/man/uniq.Rd b/man/uniq.Rd new file mode 100644 index 0000000..850a97a --- /dev/null +++ b/man/uniq.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standalone-helpers.R +\name{uniq} +\alias{uniq} +\title{Unique Values of Vector} +\usage{ +uniq(x) +} +\arguments{ +\item{x}{vector} +} +\value{ +\verb{} vector +} +\description{ +Unique Values of Vector +} +\keyword{internal} diff --git a/man/uniq_narm.Rd b/man/uniq_narm.Rd new file mode 100644 index 0000000..b24e31c --- /dev/null +++ b/man/uniq_narm.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standalone-helpers.R +\name{uniq_narm} +\alias{uniq_narm} +\title{Unique Values with NAs Removed} +\usage{ +uniq_narm(x) +} +\arguments{ +\item{x}{vector} +} +\value{ +\verb{} vector +} +\description{ +Unique Values with NAs Removed +} +\keyword{internal} diff --git a/man/uniq_vlen.Rd b/man/uniq_vlen.Rd new file mode 100644 index 0000000..cf3bad0 --- /dev/null +++ b/man/uniq_vlen.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standalone-helpers.R +\name{uniq_vlen} +\alias{uniq_vlen} +\title{Unique Lengths of Vector} +\usage{ +uniq_vlen(x) +} +\arguments{ +\item{x}{vector} +} +\value{ +\verb{} vector +} +\description{ +Unique Lengths of Vector +} +\keyword{internal} diff --git a/man/vlen.Rd b/man/vlen.Rd new file mode 100644 index 0000000..544d402 --- /dev/null +++ b/man/vlen.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standalone-helpers.R +\name{vlen} +\alias{vlen} +\title{Lengths of Vector} +\usage{ +vlen(x) +} +\arguments{ +\item{x}{vector} +} +\value{ +\verb{} vector +} +\description{ +Lengths of Vector +} +\keyword{internal}