From 46c9f4dbf8968f3697a53ae0ccc1b9cf4a674656 Mon Sep 17 00:00:00 2001 From: Andrew Bruce Date: Tue, 12 Nov 2024 14:25:35 -0800 Subject: [PATCH] added groupers and reducers --- DESCRIPTION | 2 + NAMESPACE | 17 +- R/fastverse.R | 135 +++++++++++++++ R/generated-globals.R | 39 +++++ R/groupers.R | 272 ++++++++++++++++++++++++++++++ R/grouping.R | 61 ------- R/helpers.R | 375 +----------------------------------------- R/random_hcpcs.R | 31 +++- R/reducers.R | 121 ++++++++++++++ R/split_lengths.R | 110 ------------- R/splitters.R | 170 +++++++++++++++++++ R/stringfish.R | 125 ++++++++++++++ R/vctrs.R | 44 +++++ man/empty.Rd | 2 +- man/gchop.Rd | 2 +- man/getelem.Rd | 2 +- man/group_3.Rd | 6 +- man/group_4.Rd | 25 +++ man/group_5.Rd | 25 +++ man/iif_else.Rd | 2 +- man/max_vlen.Rd | 2 +- man/not_na.Rd | 2 +- man/process_groups.Rd | 24 +++ man/random_hcpcs.Rd | 2 +- man/random_hcpcs2.Rd | 20 +++ man/red2.Rd | 26 +++ man/reduce_runs.Rd | 31 ++++ man/sf_c.Rd | 21 +++ man/sf_convert.Rd | 4 +- man/sf_detect.Rd | 2 +- man/sf_extract.Rd | 2 +- man/sf_nchar.Rd | 2 +- man/sf_remove.Rd | 2 +- man/sf_sub.Rd | 2 +- man/split_1.Rd | 2 +- man/split_at.Rd | 2 +- man/split_end.Rd | 2 +- man/split_first.Rd | 6 +- man/split_lengths.Rd | 6 +- man/splits.Rd | 2 +- man/strsort.Rd | 2 +- man/take_at.Rd | 2 +- man/uniq.Rd | 21 +++ man/uniq_narm.Rd | 2 +- man/uniq_vlen.Rd | 2 +- man/vlen.Rd | 2 +- 46 files changed, 1183 insertions(+), 576 deletions(-) create mode 100644 R/fastverse.R create mode 100644 R/groupers.R delete mode 100644 R/grouping.R create mode 100644 R/reducers.R delete mode 100644 R/split_lengths.R create mode 100644 R/splitters.R create mode 100644 R/stringfish.R create mode 100644 R/vctrs.R create mode 100644 man/group_4.Rd create mode 100644 man/group_5.Rd create mode 100644 man/process_groups.Rd create mode 100644 man/random_hcpcs2.Rd create mode 100644 man/red2.Rd create mode 100644 man/reduce_runs.Rd create mode 100644 man/sf_c.Rd create mode 100644 man/uniq.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 5795645..1aa2175 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -14,11 +14,13 @@ Imports: cheapr, collapse, data.table, + dplyr, glue, kit, purrr, rlang, stringfish, + stringi, stringr, vctrs Suggests: diff --git a/NAMESPACE b/NAMESPACE index 62e42ca..6833740 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -9,6 +9,8 @@ export(get_pin) export(getelem) export(gh_raw) export(group_3) +export(group_4) +export(group_5) export(iif_else) export(jaccard) export(letters_to_numbers) @@ -18,9 +20,14 @@ export(max_vlen) export(mount_board) export(not_na) export(parentheses) +export(process_groups) export(random_hcpcs) +export(random_hcpcs2) +export(red2) +export(reduce_runs) export(remove_redundant) export(rr) +export(sf_c) export(sf_convert) export(sf_detect) export(sf_extract) @@ -37,6 +44,7 @@ export(split_lengths) export(splits) export(strsort) export(take_at) +export(uniq) export(uniq_narm) export(uniq_vlen) export(vlen) @@ -46,11 +54,18 @@ importFrom(collapse,.c) importFrom(collapse,fcount) importFrom(collapse,fgroup_by) importFrom(collapse,fmutate) +importFrom(collapse,fselect) importFrom(collapse,fsubset) importFrom(collapse,fungroup) importFrom(collapse,groupid) importFrom(collapse,join) importFrom(data.table,data.table) -importFrom(glue,glue) +importFrom(purrr,list_c) importFrom(purrr,map) +importFrom(purrr,map_chr) +importFrom(purrr,modify_if) importFrom(stats,setNames) +importFrom(stringr,regex) +importFrom(stringr,str_extract_all) +importFrom(stringr,str_sort) +importFrom(stringr,str_split_fixed) diff --git a/R/fastverse.R b/R/fastverse.R new file mode 100644 index 0000000..13f9ee5 --- /dev/null +++ b/R/fastverse.R @@ -0,0 +1,135 @@ +#' If Else wrapper using [kit::iif()] +#' +#' @param x `` vector +#' +#' @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`. +#' +#' @returns vector of same length as `x` and attributes as `yes`. Data values +#' are taken from values of `yes` and `no`. +#' +#' @examples +#' x <- c(1:4, 3:2, 1:4) +#' +#' iif_else(x > 2L, x, x - 1L) +#' +#' @autoglobal +#' +#' @export +iif_else <- \(x, yes, no) kit::iif(test = x, yes = yes, no = no, nThread = 4L) + +#' Parallel Sort wrapper using [kit::psort()] +#' +#' @param x `` vector. If other, will default to [base::sort()] +#' +#' @returns `x` in sorted order +#' +#' @examples +#' strsort(random_hcpcs()) +#' +#' @autoglobal +#' +#' @export +strsort <- \(x) kit::psort(x, nThread = 4L) + +#' Predicate to filter out NAs +#' +#' @param x vector +#' +#' @returns `` vector +#' +#' @examples +#' c(NA, "AA") |> not_na() +#' +#' @autoglobal +#' +#' @export +not_na <- \(x) !cheapr::is_na(x) + +#' Get named element from list +#' +#' @param l named `` +#' +#' @param nm `` element name; can be a regex pattern +#' +#' @returns named `` element +#' +#' @examples +#' list(x1 = NA, x2 = "AA") |> getelem("x2") +#' +#' list(x1 = NA, x2 = "AA") |> getelem("2$") +#' +#' @autoglobal +#' +#' @export +getelem <- \(l, nm) collapse::get_elem(l = l, elem = nm, regex = TRUE) + +#' Lengths of Vector +#' +#' @param x vector +#' +#' @returns `` vector +#' +#' @examples +#' random_hcpcs(5) |> vlen() +#' +#' @autoglobal +#' +#' @export +vlen <- \(x) collapse::vlengths(x, use.names = FALSE) + +#' Unique Values of Vector +#' +#' @param x vector +#' +#' @returns vector +#' +#' @examples +#' random_hcpcs(5) |> uniq() +#' +#' @autoglobal +#' +#' @export +uniq <- \(x) collapse::funique(x) + +#' Unique Lengths of Vector +#' +#' @param x vector +#' +#' @returns `` vector +#' +#' @examples +#' random_hcpcs(5) |> uniq_vlen() +#' +#' @autoglobal +#' +#' @export +uniq_vlen <- \(x) uniq(vlen(x)) + +#' Unique Values with NAs Removed +#' +#' @param x vector +#' +#' @returns vector +#' +#' @examples +#' uniq_narm(c("A", NA, "A", 1)) +#' +#' @autoglobal +#' +#' @export +uniq_narm <- \(x) uniq(collapse::na_rm(x)) + +#' Maximum Vector Length +#' +#' @param x vector +#' +#' @returns `` vector +#' +#' @examples +#' random_hcpcs(5) |> max_vlen() +#' +#' @autoglobal +#' +#' @export +max_vlen <- \(x) collapse::fmax(vlen(x)) diff --git a/R/generated-globals.R b/R/generated-globals.R index dbbde63..9e49d11 100644 --- a/R/generated-globals.R +++ b/R/generated-globals.R @@ -2,23 +2,62 @@ utils::globalVariables(c( # + # + # "a1", # + # + # "a2", # + # + # "a3", + # + # + "a4", + # + "a5", # + # + # "code", # + # + # "G", + # + "group", + # + "grp1", + # + "grp2", # + # + # "i1", # + # + # "i2", # + # + # "i3", + # + # + "i4", + # + "i5", + # + "keys", # + # + # + # "N", + # + "value", # # "x1", diff --git a/R/groupers.R b/R/groupers.R new file mode 100644 index 0000000..0f0e5f2 --- /dev/null +++ b/R/groupers.R @@ -0,0 +1,272 @@ +#' Group Length 3 +#' +#' @param x `` of character vectors +#' +#' @returns `` of character vectors +#' +#' @examples +#' c("C75", "C97", "G02", "G04") |> +#' split_lengths() |> +#' remove_redundant() |> +#' split_first() |> +#' group_3() +#' +#' @importFrom collapse %!in% fgroup_by fmutate fungroup fcount fsubset join groupid +#' @importFrom purrr map +#' @importFrom data.table data.table +#' +#' @export +#' +#' @autoglobal +group_3 <- function(x) { + x <- getelem(x, "x3") + + if (empty(x)) + return(x) + + map(x, function(x) { + idx <- data.table( + code = x, + grp = sf_sub(x, 1, 2), + a1 = take_at(x), + a2 = take_at(x, 2), + a3 = take_at(x, 3), + i1 = groupid(take_at(x)) + ) |> + fgroup_by(a1) |> fmutate(i2 = groupid(a2)) |> + fgroup_by(a1, a2) |> fmutate(i3 = groupid(a3)) |> + fungroup() + + lone <- fcount(idx, i1, add = TRUE) |> + fsubset((i2 + i3 + N) == 3) + + last <- fsubset(idx, code %!in% lone[["code"]]) + + last <- join( + fcount(last, a1, a2), + fcount(last, a1, name = "G"), + on = "a1", + verbose = 0 + ) |> + fsubset(N == G) |> + join(last, + on = c("a1", "a2"), + how = "right", + verbose = 0) |> + fsubset(not_na(N)) + + rest <- fsubset(idx, code %!in% c(lone[["code"]], last[["code"]])) + + c( + if (empty(lone)) + NULL + else + list(lone[["code"]]), + if (empty(last)) + NULL + else + gchop(last[["code"]], last[["a1"]]), + if (empty(rest)) + NULL + else + gchop(rest[["code"]], rest[["grp"]]) + ) + }) +} + +#' Group Length 4 +#' +#' @param x `` of character vectors +#' +#' @returns `` of character vectors +#' +#' @examples +#' c("C75", "C97", "G02", "G04") |> +#' split_lengths() |> +#' remove_redundant() |> +#' split_first() |> +#' group_4() +#' +#' @importFrom collapse %!in% fgroup_by fmutate fungroup fcount fsubset join groupid +#' @importFrom purrr map +#' @importFrom data.table data.table +#' +#' @export +#' +#' @autoglobal +group_4 <- function(x) { + x <- getelem(x, "x4") + + if (empty(x)) + return(x) + + map(x, function(x) { + idx <- data.table( + code = x, + grp1 = sf_sub(x, 1, 2), + grp2 = sf_sub(x, 1, 3), + a1 = take_at(x), + a2 = take_at(x, 2), + a3 = take_at(x, 3), + a4 = take_at(x, 4), + i1 = groupid(take_at(x)) + ) |> + fgroup_by(a1) |> + fmutate(i2 = groupid(a2)) |> + fgroup_by(a1, a2) |> + fmutate(i3 = groupid(a3)) |> + fgroup_by(a1, a2, a3) |> + fmutate(i4 = groupid(a4)) |> + fungroup() + + lone <- fcount(idx, i1, add = TRUE) |> + fsubset((i2 + i3 + i4 + N) == 4) + + last <- fsubset(idx, code %!in% lone[["code"]]) + + last <- join( + fcount(last, grp1, a3), + fcount(last, grp1, name = "G"), + on = "grp1", + verbose = 0 + ) |> + fsubset(N == G) |> + join( + last, + on = c("grp1", "a3"), + how = "right", + verbose = 0 + ) |> + fsubset(not_na(N)) + + rest <- fsubset(idx, code %!in% c(lone[["code"]], last[["code"]])) + + c( + if (empty(lone)) + NULL + else + list(lone[["code"]]), + if (empty(last)) + NULL + else + gchop(last[["code"]], last[["grp1"]]), + if (empty(rest)) + NULL + else + gchop(rest[["code"]], rest[["grp2"]]) + ) + }) +} + +#' Group Length 5 +#' +#' @param x `` of character vectors +#' +#' @returns `` of character vectors +#' +#' @examples +#' c("C75", "C97", "G02", "G04") |> +#' split_lengths() |> +#' remove_redundant() |> +#' split_first() |> +#' group_5() +#' +#' @importFrom collapse %!in% fgroup_by fmutate fungroup fcount fsubset join groupid +#' @importFrom purrr map +#' @importFrom data.table data.table +#' +#' @autoglobal +#' +#' @export +group_5 <- function(x) { + x <- getelem(x, "x5") + + if (empty(x)) + return(x) + + map(x, function(x) { + idx <- data.table( + code = x, + grp1 = sf_sub(x, 1, 2), + grp2 = sf_sub(x, 1, 3), + grp3 = sf_sub(x, 1, 4), + a1 = take_at(x), + a2 = take_at(x, 2), + a3 = take_at(x, 3), + a4 = take_at(x, 4), + a5 = take_at(x, 5), + i1 = groupid(take_at(x)) + ) |> + fgroup_by(a1) |> + fmutate(i2 = groupid(a2)) |> + fgroup_by(a1, a2) |> + fmutate(i3 = groupid(a3)) |> + fgroup_by(a1, a2, a3) |> + fmutate(i4 = groupid(a4)) |> + fgroup_by(a1, a2, a3, a4) |> + fmutate(i5 = groupid(a5)) |> + fungroup() + + lone <- fcount(idx, i1, add = TRUE) |> + fsubset((i2 + i3 + i4 + i5 + N) == 5) + + last <- fsubset(idx, code %!in% lone[["code"]]) + + last <- join( + fcount(last, grp2, a4), + fcount(last, grp2, name = "G"), + on = "grp2", + verbose = 0 + ) |> + fsubset(N == G) |> + join( + last, + on = c("grp2", "a4"), + how = "right", + verbose = 0 + ) |> + fsubset(not_na(N)) + + rest <- fsubset(idx, code %!in% c(lone[["code"]], last[["code"]])) + + c( + if (empty(lone)) + NULL + else + list(lone[["code"]]), + if (empty(last)) + NULL + else + gchop(last[["code"]], last[["grp2"]]), + if (empty(rest)) + NULL + else + gchop(rest[["code"]], rest[["grp3"]]) + ) + }) +} + +#' Process Groups +#' +#' @param x `` of character vectors +#' +#' @returns `` of character vectors +#' +#' @examples +#' random_hcpcs(10) |> +#' split_lengths() |> +#' remove_redundant() |> +#' split_first() |> +#' process_groups() +#' @autoglobal +#' +#' @export +process_groups <- function(x) { + list( + g1 = x$x1, + g2 = x$x2, + g3 = group_3(x), + g4 = group_4(x), + g5 = group_5(x) + ) +} diff --git a/R/grouping.R b/R/grouping.R deleted file mode 100644 index c4a48df..0000000 --- a/R/grouping.R +++ /dev/null @@ -1,61 +0,0 @@ -#' Group 3 -#' -#' @param x `` of character vectors -#' -#' @returns `` of character vectors -#' -#' @examples -#' c("C75", "C97", "G02", "G04") |> -#' split_lengths() |> -#' remove_redundant() |> -#' split_first() |> -#' group_3() -#' -#' @importFrom collapse %!in% fgroup_by fmutate fungroup fcount fsubset join groupid -#' @importFrom purrr map -#' @importFrom data.table data.table -#' -#' @export -#' -#' @autoglobal -group_3 <- function(x) { - - x <- getelem(x, "x3") - - if (empty(x)) return(x) - - map(x, function(x) { - - idx <- data.table( - code = x, - grp = sf_sub(x, 1, 2), - a1 = take_at(x), - a2 = take_at(x, 2), - a3 = take_at(x, 3), - i1 = groupid(take_at(x))) |> - fgroup_by(a1) |> fmutate(i2 = groupid(a2)) |> - fgroup_by(a1, a2) |> fmutate(i3 = groupid(a3)) |> - fungroup() - - lone <- fcount(idx, i1, add = TRUE) |> - fsubset((i2 + i3 + N) == 3) - - last <- fsubset(idx, code %!in% lone[["code"]]) - - last <- join( - fcount(last, a1, a2), - fcount(last, a1, name = "G"), - on = "a1", verbose = 0) |> - fsubset(N == G) |> - join(last, on = c("a1", "a2"), - how = "right", - verbose = 0) |> - fsubset(not_na(N)) - - rest <- fsubset(idx, code %!in% c(lone[["code"]], last[["code"]])) - - c(if (empty(lone)) NULL else list(lone[["code"]]), - if (empty(last)) NULL else gchop(last[["code"]], last[["a1"]]), - if (empty(rest)) NULL else gchop(rest[["code"]], rest[["grp"]])) - }) -} diff --git a/R/helpers.R b/R/helpers.R index a38cd77..fb63253 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -1,322 +1,3 @@ -#' If Else wrapper using [kit::iif()] -#' -#' @param x `` vector -#' -#' @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`. -#' -#' @returns vector of same length as `x` and attributes as `yes`. Data values -#' are taken from values of `yes` and `no`. -#' -#' @examples -#' x <- c(1:4, 3:2, 1:4) -#' -#' iif_else(x > 2L, x, x - 1L) -#' -#' @autoglobal -#' -#' @export -iif_else <- \(x, yes, no) kit::iif(test = x, yes = yes, no = no, nThread = 4L) - -#' Parallel Sort wrapper using [kit::psort()] -#' -#' @param x `` vector. If other, will default to [base::sort()] -#' -#' @returns `x` in sorted order -#' -#' @examples -#' strsort(random_hcpcs()) -#' -#' @autoglobal -#' -#' @export -strsort <- \(x) kit::psort(x, nThread = 4L) - -#' Predicate to filter out NAs -#' -#' @param x vector -#' -#' @returns `` vector -#' -#' @examples -#' c(NA, "AA") |> not_na() -#' -#' @autoglobal -#' -#' @export -not_na <- \(x) !cheapr::is_na(x) - -#' Get named element from list -#' -#' @param l named `` -#' -#' @param nm `` element name; can be a regex pattern -#' -#' @returns named `` element -#' -#' @examples -#' list(x1 = NA, x2 = "AA") |> getelem("x2") -#' -#' list(x1 = NA, x2 = "AA") |> getelem("2$") -#' -#' @autoglobal -#' -#' @export -getelem <- \(l, nm) collapse::get_elem(l = l, elem = nm, regex = TRUE) - -#' Lengths of Vector -#' -#' @param x vector -#' -#' @returns `` vector -#' -#' @examples -#' random_hcpcs(5) |> vlen() -#' -#' @autoglobal -#' -#' @export -vlen <- \(x) collapse::vlengths(x, use.names = FALSE) - -#' Unique Lengths of Vector -#' -#' @param x vector -#' -#' @returns `` vector -#' -#' @examples -#' random_hcpcs(5) |> uniq_vlen() -#' -#' @autoglobal -#' -#' @export -uniq_vlen <- \(x) collapse::funique(vlen(x)) - -#' Unique Values with NAs Removed -#' -#' @param x vector -#' -#' @returns vector -#' -#' @examples -#' uniq_narm(c("A", NA, "A", 1)) -#' -#' @autoglobal -#' -#' @export -uniq_narm <- \(x) collapse::funique(collapse::na_rm(x)) - -#' Maximum Vector Length -#' -#' @param x vector -#' -#' @returns `` vector -#' -#' @examples -#' random_hcpcs(5) |> max_vlen() -#' -#' @autoglobal -#' -#' @export -max_vlen <- \(x) collapse::fmax(vlen(x)) - -#' Is Vector Empty? -#' -#' @param x vector -#' -#' @returns `` -#' -#' @examples -#' empty(character(0)) -#' -#' empty(c()) -#' -#' empty(NULL) -#' -#' empty(NA) -#' -#' empty(list()) -#' -#' empty(list(character(0))) -#' -#' empty(list(x = character(0))) -#' -#' @autoglobal -#' -#' @export -empty <- \(x) vctrs::vec_is_empty(x) - -#' Chop Vector by Group -#' -#' @param v `` vector -#' -#' @param g `` group -#' -#' @returns `` -#' -#' @examples -#' (v <- random_hcpcs(2)) -#' -#' (g <- sample(1:2, size = length(v), replace = TRUE)) -#' -#' gchop(v, g) -#' @autoglobal -#' -#' @export -gchop <- \(v, g) vctrs::vec_chop(x = v, sizes = vctrs::vec_run_sizes(g)) - -#' Subset Vector by Range -#' -#' @param x `` vector -#' -#' @param start `` index start; default is `1` -#' -#' @param stop `` index end -#' -#' @returns `` vector -#' -#' @examples -#' sf_sub(random_hcpcs(2), 1, 2) -#' -#' @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 -#' -#' @returns `` stringfish vector -#' -#' @examples -#' sf_convert(random_hcpcs(500)) -#' -#' @autoglobal -#' -#' @export -sf_convert <- \(x) stringfish::convert_to_sf(x) - -#' Count number of characters in character vector -#' -#' @param x `` vector -#' -#' @returns `` stringfish vector -#' -#' @examples -#' sf_nchar(random_hcpcs()) -#' -#' @autoglobal -#' -#' @export -sf_nchar <- \(x) stringfish::sf_nchar(x, nthreads = 4L) - -#' Subset Vector at Index -#' -#' @param x `` vector -#' -#' @param start `` index -#' -#' @returns `` vector -#' -#' @examples -#' take_at(random_hcpcs(2), 2) -#' -#' @autoglobal -#' -#' @export -take_at <- \(x, start = 1) sf_sub(x, start = start, stop = start) - -#' Split Vector by Index Subset -#' -#' @param x `` vector -#' -#' @param y `` vector; default is `x` -#' -#' @param start `` index start -#' -#' @param stop `` index end -#' -#' @returns `` vector -#' -#' @examples -#' x <- c("0741T", "E0628", "L4387", "0360T", "1127F", "0002M") -#' -#' (end <- sf_extract(x, "[A-Z]$")) -#' -#' (beg <- paste0(take_at(end, 5), sf_remove(end, "[A-Z]$"))) -#' -#' split_at(x = end, y = beg, start = 1, stop = 2) -#' -#' @autoglobal -#' -#' @export -split_at <- \(x, y = x, start, stop) collapse::rsplit(x, sf_sub(x = y, start = start, stop = stop), use.names = FALSE) - -#' Split Vector -#' -#' @param x `` vector -#' -#' @returns `` vector -#' -#' @examples -#' split_1(c("AA", strrep(LETTERS[1:5], 2), "Z")) -#' -#' @autoglobal -#' -#' @export -split_1 <- \(x) split_at(x, y = x, start = 1, stop = 1) - -#' Detect by Regex -#' -#' @param s `` vector -#' -#' @param p `` regex pattern -#' -#' @returns `` vector -#' -#' @examples -#' sf_detect(random_hcpcs(), "[A-Z]{1}") -#' -#' @autoglobal -#' -#' @export -sf_detect <- \(s, p) stringfish::sf_grepl(s, p, nthreads = 4L) - -#' Extract by Regex -#' -#' @param s `` vector -#' -#' @param p `` regex pattern -#' -#' @returns `` vector -#' -#' @examples -#' sf_extract(random_hcpcs(), "[A-Z]{1}") -#' -#' @autoglobal -#' -#' @export -sf_extract <- \(s, p) s[sf_detect(s, p)] - -#' Remove by Regex -#' -#' @param s `` vector -#' -#' @param p `` regex pattern -#' -#' @returns `` vector -#' -#' @examples -#' sf_remove(LETTERS, "A") -#' -#' sf_remove(paste0(LETTERS, collapse = ""), "A") -#' -#' @autoglobal -#' -#' @export -sf_remove <- \(s, p) stringfish::sf_gsub(s, p, "", nthreads = 4L) - #' Collapse a vector to length 1 #' #' @param ... `` string @@ -349,43 +30,6 @@ smush <- \(...) paste0(..., collapse = "") #' @export delist <- \(x) unlist(x, use.names = FALSE) -#' Delist, Unname and Split a String -#' -#' @param x `` string or named `` -#' -#' @returns Unnamed `` of split `` vectors -#' -#' @examples -#' # unnamed vector -#' splits("XYZ") -#' -#' # named vector -#' splits(c(x = "XYZ")) -#' -#' # unnamed list with one element -#' splits(list("XYZ")) -#' -#' # unnamed list with multiple elements -#' splits(list("YYY", "ZZZ")) -#' -#' # named list with one element -#' splits(list(x = "XYZ")) -#' -#' # named list with multiple elements -#' splits(list(x = "YYY", xx = "ZZZ")) -#' -#' @autoglobal -#' -#' @export -splits <- \(x) { - - res <- strsplit(delist(x), "") - - if (length(res) == 1) return(res[[1]]) - - res -} - #' Wrap A String in Brackets #' #' @param x `` string @@ -425,25 +69,18 @@ parentheses <- \(x) smush(r"--{(}--", x, r"--{)}--") #' #' sort_order(x) #' +#' @importFrom purrr list_c +#' @importFrom stringr str_extract_all str_sort regex +#' #' @autoglobal #' #' @export sort_order <- \(x) { + sort <- str_sort(x, numeric = TRUE) - sort <- stringr::str_sort(x, numeric = TRUE) - - alph <- purrr::list_c( - stringr::str_extract_all( - sort, - stringr::regex("[A-Z]") - ) - ) + alph <- list_c(str_extract_all(sort, regex("[A-Z]"))) - numb <- purrr::list_c( - stringr::str_extract_all( - sort, stringr::regex("[0-9]") - ) - ) + numb <- list_c(str_extract_all(sort, regex("[0-9]"))) smush(smush(alph), smush(numb)) } diff --git a/R/random_hcpcs.R b/R/random_hcpcs.R index 5786bb7..d36304c 100644 --- a/R/random_hcpcs.R +++ b/R/random_hcpcs.R @@ -5,7 +5,7 @@ #' @returns `` vector #' #' @examples -#' random_hcpcs(n = 5) +#' random_hcpcs() #' @export #' #' @autoglobal @@ -20,3 +20,32 @@ random_hcpcs <- function(n = 10) { sf_sub(sample(h, n), stop = 5) ) } + +#' Generate Random HCPCS Codes Vector (Version 2) +#' +#' @param n `` number of codes; default is `10` +#' +#' @returns `` vector +#' +#' @examples +#' random_hcpcs2() +#' @export +#' +#' @autoglobal +random_hcpcs2 <- function(n = 10) { + + p <- sf_c(sf_extract(LETTERS, "[^DINOW-Z]"), 0:9) + + h <- sf_convert(get_pin("hcpcs_vec")) + + sf_convert( + c( + cheapr::sample_(x = p, size = sample.int(5, 1)), + sf_sub(cheapr::sample_(x = h, size = n), stop = 2), + sf_sub(cheapr::sample_(x = h, size = n), stop = 3), + sf_sub(cheapr::sample_(x = h, size = n), stop = 4), + sf_sub(cheapr::sample_(x = h, size = n), stop = 5) + ) + ) + +} diff --git a/R/reducers.R b/R/reducers.R new file mode 100644 index 0000000..9c52b5e --- /dev/null +++ b/R/reducers.R @@ -0,0 +1,121 @@ +#' Reduce Runs +#' +#' @param x `` of character vectors +#' +#' @returns `` of character vectors +#' +#' @examples +#' x <- random_hcpcs2(20) |> +#' split_lengths() |> +#' split_first() |> +#' process_groups() +#' +#' delist(x$g2) |> +#' stringr::str_split_fixed("", max_vlen(x$g2)) |> +#' as.data.frame() |> +#' purrr::map(uniq_narm) |> +#' purrr::map(sort_order) |> +#' purrr::map(reduce_runs) +#' +#' @importFrom collapse %!in% fgroup_by fungroup fcount fsubset join groupid fselect +#' @importFrom purrr map list_c +#' @importFrom data.table data.table +#' +#' @autoglobal +#' +#' @export +reduce_runs <- function(x) { + if (sf_nchar(x) == 1) + return(x) + + test <- setNames(rep(0, 37), c(0:9, "&", LETTERS)) + + vec <- test[c(splits(x), "&")] + + vec <- vec[not_na(vec)] + + test[names(vec)] <- 1 + + test[names(test) == "&"] <- 0 + + groups <- data.table(value = names(test), + keys = test, + group = groupid(test)) |> + fgroup_by(group) + + groups <- join(groups, + fcount(groups, group), + on = "group", + verbose = 0) |> + fungroup() |> + fsubset(keys == 1) |> + fsubset(N >= 3) |> + fselect(value, group) + + if (empty(groups)) + return(x) + + xgroups <- gchop(groups$value, groups$group) |> + map(smush) |> + list_c() + + if (all(xgroups == smush(c(0:9, "&", LETTERS)))) + return("[A-Z0-9]") + + replacements <- dplyr::left_join( + dplyr::slice_min(groups, by = group, order_by = value) |> dplyr::rename(start = value), + dplyr::slice_max(groups, by = group, order_by = value) |> dplyr::rename(end = value), + by = dplyr::join_by(group) + ) |> + glue::glue_data("{start}-{end}") |> + as.vector() + + res <- stringi::stri_replace_all_regex(x, xgroups, replacements, vectorize_all = FALSE) + + bracket(res) +} + +#' Reduce Length 2 +#' +#' @param x `` of character vectors +#' +#' @returns `` of character vectors +#' +#' @examples +#' x <- random_hcpcs(20) |> +#' split_lengths() |> +#' split_first() |> +#' process_groups() +#' +#' red2(x) +#' +#' @importFrom purrr map map_chr modify_if +#' @importFrom stringr str_split_fixed +#' +#' @autoglobal +#' +#' @export +red2 <- function(x) { + x <- getelem(x, "g2") + + if (empty(x)) + return(character(0)) + + length_gto <- \(x) length(x) > 1 + + modify_if(x, length_gto, function(x) { + parts <- str_split_fixed(x, "", max_vlen(x)) |> + as.data.frame() |> + map(uniq_narm) |> + map(sort_order) |> + map(reduce_runs) |> + delist() + + multi <- sf_nchar(parts) > 1 + nobrk <- !sf_detect(parts[multi], "\\[|\\]") + + parts[multi] <- iif_else(any(nobrk), map_chr(parts[multi], bracket), parts[multi]) + + smush(parts) + }) +} diff --git a/R/split_lengths.R b/R/split_lengths.R deleted file mode 100644 index fd29861..0000000 --- a/R/split_lengths.R +++ /dev/null @@ -1,110 +0,0 @@ -#' Split Character Vector by Lengths -#' -#' @param x `` vector -#' -#' @param verbose `` print output -#' -#' @returns `` of character vectors -#' -#' @examples -#' random_hcpcs(5) |> -#' split_lengths() -#' -#' @autoglobal -#' -#' @export -split_lengths <- function(x, verbose = FALSE) { - - stopifnot(is.character(x)) - - x <- sf_remove(x, "\\*|\\s") |> - uniq_narm() |> - strsort() - - l <- vlen(x) - - out <- list( - x1 = x[l == 1], - x2 = x[l == 2], - x3 = x[l == 3], - x4 = x[l == 4], - x5 = x[l == 5]) - - if (verbose) { - return(invisible(out)) - } else { - return(out) - } -} - -#' Split Character Vector at End -#' -#' @param x `` vector -#' -#' @returns `` of character vectors -#' -#' @examples -#' x <- random_hcpcs(10) |> -#' split_lengths() |> -#' remove_redundant() -#' -#' split_end(x$x5) -#' -#' @importFrom glue glue -#' -#' @autoglobal -#' -#' @export -split_end <- \(x) { - - if (any(sf_detect(x, "[A-Z]$"))) { - - end <- sf_extract(x, "[A-Z]$") - beg <- glue("{take_at(end, 5)}{sf_remove(end, '[A-Z]$')}") - - c(split_at(x = x[!sf_detect(x, "[A-Z]$")], start = 1, stop = 1), - split_at(x = end, y = beg, start = 1, stop = 2)) - - } else { - - split_at(x, start = 1, stop = 1) - - } -} - -#' Split Character Vector by Lengths -#' -#' @param x `` vector -#' -#' @param verbose `` print output -#' -#' @returns `` of character vectors -#' -#' @examples -#' random_hcpcs(5) |> -#' split_lengths() |> -#' remove_redundant() |> -#' split_first() -#' -#' @importFrom collapse %=% .c -#' -#' @autoglobal -#' -#' @export -split_first <- function(x, verbose = FALSE) { - - .c(x1, x2, x3, x4, x5) %=% x - - out <- list( - x1 = list(x1), - x2 = split_1(x2), - x3 = split_1(x3), - x4 = split_1(x4), - x5 = split_end(x5)) - - if (verbose) { - return(invisible(out)) - } else { - return(out) - } -} diff --git a/R/splitters.R b/R/splitters.R new file mode 100644 index 0000000..c715aa4 --- /dev/null +++ b/R/splitters.R @@ -0,0 +1,170 @@ +#' Split Character Vector by Lengths +#' +#' @param x `` vector +#' +#' @returns `` of character vectors +#' +#' @examples +#' random_hcpcs(5) |> +#' split_lengths() +#' +#' @autoglobal +#' +#' @export +split_lengths <- function(x) { + + stopifnot(is.character(x)) + + x <- sf_remove(x, "\\*|\\s") |> + uniq_narm() |> + strsort() + + l <- vlen(x) + + list( + x1 = x[l == 1], + x2 = x[l == 2], + x3 = x[l == 3], + x4 = x[l == 4], + x5 = x[l == 5]) +} + +#' Split Character Vector by Lengths +#' +#' @param x `` vector +#' +#' @returns `` of character vectors +#' +#' @examples +#' random_hcpcs(5) |> +#' split_lengths() |> +#' remove_redundant() |> +#' split_first() +#' +#' @importFrom collapse %=% .c +#' +#' @autoglobal +#' +#' @export +split_first <- function(x) { + + .c(x1, x2, x3, x4, x5) %=% x + + list( + x1 = list(x1), + x2 = split_1(x2), + x3 = split_1(x3), + x4 = split_1(x4), + x5 = split_end(x5)) +} + +#' Split Vector by Index Subset +#' +#' @param x `` vector +#' +#' @param y `` vector; default is `x` +#' +#' @param start `` index start +#' +#' @param stop `` index end +#' +#' @returns `` vector +#' +#' @examples +#' x <- c("0741T", "E0628", "L4387", "0360T", "1127F", "0002M") +#' +#' (end <- sf_extract(x, "[A-Z]$")) +#' +#' (beg <- paste0(take_at(end, 5), sf_remove(end, "[A-Z]$"))) +#' +#' split_at(x = end, y = beg, start = 1, stop = 2) +#' +#' @autoglobal +#' +#' @export +split_at <- \(x, y = x, start, stop) collapse::rsplit(x, sf_sub(x = y, start = start, stop = stop), use.names = FALSE) + +#' Split Vector +#' +#' @param x `` vector +#' +#' @returns `` vector +#' +#' @examples +#' split_1(c("AA", strrep(LETTERS[1:5], 2), "Z")) +#' +#' @autoglobal +#' +#' @export +split_1 <- \(x) split_at(x, y = x, start = 1, stop = 1) + +#' Split Character Vector at End +#' +#' @param x `` vector +#' +#' @returns `` of character vectors +#' +#' @examples +#' x <- random_hcpcs(10) |> +#' split_lengths() |> +#' remove_redundant() +#' +#' split_end(x$x5) +#' +#' @autoglobal +#' +#' @export +split_end <- \(x) { + + if (any(sf_detect(x, "[A-Z]$"))) { + + end <- sf_extract(x, "[A-Z]$") + beg <- paste0(take_at(end, 5), sf_remove(end, "[A-Z]$")) + # beg <- glue("{take_at(end, 5)}{sf_remove(end, '[A-Z]$')}") + + c(split_at(x = x[!sf_detect(x, "[A-Z]$")], start = 1, stop = 1), + split_at(x = end, y = beg, start = 1, stop = 2)) + + } else { + + split_at(x, start = 1, stop = 1) + + } +} + +#' Delist, Unname and Split a String +#' +#' @param x `` string or named `` +#' +#' @returns Unnamed `` of split `` vectors +#' +#' @examples +#' # unnamed vector +#' splits("XYZ") +#' +#' # named vector +#' splits(c(x = "XYZ")) +#' +#' # unnamed list with one element +#' splits(list("XYZ")) +#' +#' # unnamed list with multiple elements +#' splits(list("YYY", "ZZZ")) +#' +#' # named list with one element +#' splits(list(x = "XYZ")) +#' +#' # named list with multiple elements +#' splits(list(x = "YYY", xx = "ZZZ")) +#' +#' @autoglobal +#' +#' @export +splits <- \(x) { + + res <- strsplit(delist(x), "") + + if (length(res) == 1) return(res[[1]]) + + res +} diff --git a/R/stringfish.R b/R/stringfish.R new file mode 100644 index 0000000..fe17a47 --- /dev/null +++ b/R/stringfish.R @@ -0,0 +1,125 @@ +#' Subset Vector by Range +#' +#' @param x `` vector +#' +#' @param start `` index start; default is `1` +#' +#' @param stop `` index end +#' +#' @returns `` vector +#' +#' @examples +#' sf_sub(random_hcpcs(2), 1, 2) +#' +#' @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 +#' +#' @returns `` stringfish vector +#' +#' @examples +#' sf_convert(random_hcpcs(50)) +#' +#' @autoglobal +#' +#' @export +sf_convert <- \(x) stringfish::convert_to_sf(x) + +#' Count number of characters in character vector +#' +#' @param x `` vector +#' +#' @returns `` stringfish vector +#' +#' @examples +#' sf_nchar(random_hcpcs()) +#' +#' @autoglobal +#' +#' @export +sf_nchar <- \(x) stringfish::sf_nchar(x, nthreads = 4L) + +#' Subset Vector at Index +#' +#' @param x `` vector +#' +#' @param start `` index +#' +#' @returns `` vector +#' +#' @examples +#' take_at(random_hcpcs(2), 2) +#' +#' @autoglobal +#' +#' @export +take_at <- \(x, start = 1) sf_sub(x, start = start, stop = start) + +#' Detect by Regex +#' +#' @param s `` vector +#' +#' @param p `` regex pattern +#' +#' @returns `` vector +#' +#' @examples +#' sf_detect(random_hcpcs(), "[A-Z]{1}") +#' +#' @autoglobal +#' +#' @export +sf_detect <- \(s, p) stringfish::sf_grepl(s, p, nthreads = 4L) + +#' Extract by Regex +#' +#' @param s `` vector +#' +#' @param p `` regex pattern +#' +#' @returns `` vector +#' +#' @examples +#' sf_extract(random_hcpcs(), "[A-Z]{1}") +#' +#' @autoglobal +#' +#' @export +sf_extract <- \(s, p) s[sf_detect(s, p)] + +#' Remove by Regex +#' +#' @param s `` vector +#' +#' @param p `` regex pattern +#' +#' @returns `` vector +#' +#' @examples +#' sf_remove(LETTERS, "A") +#' +#' sf_remove(paste0(LETTERS, collapse = ""), "A") +#' +#' @autoglobal +#' +#' @export +sf_remove <- \(s, p) stringfish::sf_gsub(s, p, "", nthreads = 4L) + +#' Concatenate Vectors +#' +#' @param ... Any number of vectors, coerced to `` vector, if necessary +#' +#' @returns concatenated `` vector +#' +#' @examples +#' sf_c(LETTERS, "A") +#' +#' @autoglobal +#' +#' @export +sf_c <- \(...) stringfish::sfc(...) diff --git a/R/vctrs.R b/R/vctrs.R new file mode 100644 index 0000000..95a7515 --- /dev/null +++ b/R/vctrs.R @@ -0,0 +1,44 @@ +#' Is Vector Empty? +#' +#' @param x vector +#' +#' @returns `` +#' +#' @examples +#' empty(character(0)) +#' +#' empty(c()) +#' +#' empty(NULL) +#' +#' empty(NA) +#' +#' empty(list()) +#' +#' empty(list(character(0))) +#' +#' empty(list(x = character(0))) +#' +#' @autoglobal +#' +#' @export +empty <- \(x) vctrs::vec_is_empty(x) + +#' Chop Vector by Group +#' +#' @param v `` vector +#' +#' @param g `` group +#' +#' @returns `` +#' +#' @examples +#' (v <- random_hcpcs(2)) +#' +#' (g <- sample(1:2, size = length(v), replace = TRUE)) +#' +#' gchop(v, g) +#' @autoglobal +#' +#' @export +gchop <- \(v, g) vctrs::vec_chop(x = v, sizes = vctrs::vec_run_sizes(g)) diff --git a/man/empty.Rd b/man/empty.Rd index f057819..45bc7d7 100644 --- a/man/empty.Rd +++ b/man/empty.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/helpers.R +% Please edit documentation in R/vctrs.R \name{empty} \alias{empty} \title{Is Vector Empty?} diff --git a/man/gchop.Rd b/man/gchop.Rd index 38a2c95..692ad69 100644 --- a/man/gchop.Rd +++ b/man/gchop.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/helpers.R +% Please edit documentation in R/vctrs.R \name{gchop} \alias{gchop} \title{Chop Vector by Group} diff --git a/man/getelem.Rd b/man/getelem.Rd index c4658c5..c6a4c14 100644 --- a/man/getelem.Rd +++ b/man/getelem.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/helpers.R +% Please edit documentation in R/fastverse.R \name{getelem} \alias{getelem} \title{Get named element from list} diff --git a/man/group_3.Rd b/man/group_3.Rd index 7d3e8aa..4aa3fb9 100644 --- a/man/group_3.Rd +++ b/man/group_3.Rd @@ -1,8 +1,8 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/grouping.R +% Please edit documentation in R/groupers.R \name{group_3} \alias{group_3} -\title{Group 3} +\title{Group Length 3} \usage{ group_3(x) } @@ -13,7 +13,7 @@ group_3(x) \verb{} of character vectors } \description{ -Group 3 +Group Length 3 } \examples{ c("C75", "C97", "G02", "G04") |> diff --git a/man/group_4.Rd b/man/group_4.Rd new file mode 100644 index 0000000..5ed8fd2 --- /dev/null +++ b/man/group_4.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/groupers.R +\name{group_4} +\alias{group_4} +\title{Group Length 4} +\usage{ +group_4(x) +} +\arguments{ +\item{x}{\verb{} of character vectors} +} +\value{ +\verb{} of character vectors +} +\description{ +Group Length 4 +} +\examples{ +c("C75", "C97", "G02", "G04") |> + split_lengths() |> + remove_redundant() |> + split_first() |> + group_4() + +} diff --git a/man/group_5.Rd b/man/group_5.Rd new file mode 100644 index 0000000..f098676 --- /dev/null +++ b/man/group_5.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/groupers.R +\name{group_5} +\alias{group_5} +\title{Group Length 5} +\usage{ +group_5(x) +} +\arguments{ +\item{x}{\verb{} of character vectors} +} +\value{ +\verb{} of character vectors +} +\description{ +Group Length 5 +} +\examples{ +c("C75", "C97", "G02", "G04") |> + split_lengths() |> + remove_redundant() |> + split_first() |> + group_5() + +} diff --git a/man/iif_else.Rd b/man/iif_else.Rd index 9b45ea9..5f58188 100644 --- a/man/iif_else.Rd +++ b/man/iif_else.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/helpers.R +% Please edit documentation in R/fastverse.R \name{iif_else} \alias{iif_else} \title{If Else wrapper using \code{\link[kit:iif]{kit::iif()}}} diff --git a/man/max_vlen.Rd b/man/max_vlen.Rd index 3327505..4acda21 100644 --- a/man/max_vlen.Rd +++ b/man/max_vlen.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/helpers.R +% Please edit documentation in R/fastverse.R \name{max_vlen} \alias{max_vlen} \title{Maximum Vector Length} diff --git a/man/not_na.Rd b/man/not_na.Rd index d82fdf1..0654377 100644 --- a/man/not_na.Rd +++ b/man/not_na.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/helpers.R +% Please edit documentation in R/fastverse.R \name{not_na} \alias{not_na} \title{Predicate to filter out NAs} diff --git a/man/process_groups.Rd b/man/process_groups.Rd new file mode 100644 index 0000000..9728156 --- /dev/null +++ b/man/process_groups.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/groupers.R +\name{process_groups} +\alias{process_groups} +\title{Process Groups} +\usage{ +process_groups(x) +} +\arguments{ +\item{x}{\verb{} of character vectors} +} +\value{ +\verb{} of character vectors +} +\description{ +Process Groups +} +\examples{ +random_hcpcs(10) |> + split_lengths() |> + remove_redundant() |> + split_first() |> + process_groups() +} diff --git a/man/random_hcpcs.Rd b/man/random_hcpcs.Rd index c0b82ab..9486526 100644 --- a/man/random_hcpcs.Rd +++ b/man/random_hcpcs.Rd @@ -16,5 +16,5 @@ random_hcpcs(n = 10) Generate Random HCPCS Codes Vector } \examples{ -random_hcpcs(n = 5) +random_hcpcs() } diff --git a/man/random_hcpcs2.Rd b/man/random_hcpcs2.Rd new file mode 100644 index 0000000..91b8cca --- /dev/null +++ b/man/random_hcpcs2.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/random_hcpcs.R +\name{random_hcpcs2} +\alias{random_hcpcs2} +\title{Generate Random HCPCS Codes Vector (Version 2)} +\usage{ +random_hcpcs2(n = 10) +} +\arguments{ +\item{n}{\verb{} number of codes; default is \code{10}} +} +\value{ +\verb{} vector +} +\description{ +Generate Random HCPCS Codes Vector (Version 2) +} +\examples{ +random_hcpcs2() +} diff --git a/man/red2.Rd b/man/red2.Rd new file mode 100644 index 0000000..05031bd --- /dev/null +++ b/man/red2.Rd @@ -0,0 +1,26 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/reducers.R +\name{red2} +\alias{red2} +\title{Reduce Length 2} +\usage{ +red2(x) +} +\arguments{ +\item{x}{\verb{} of character vectors} +} +\value{ +\verb{} of character vectors +} +\description{ +Reduce Length 2 +} +\examples{ +x <- random_hcpcs(20) |> + split_lengths() |> + split_first() |> + process_groups() + +red2(x) + +} diff --git a/man/reduce_runs.Rd b/man/reduce_runs.Rd new file mode 100644 index 0000000..3d31b70 --- /dev/null +++ b/man/reduce_runs.Rd @@ -0,0 +1,31 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/reducers.R +\name{reduce_runs} +\alias{reduce_runs} +\title{Reduce Runs} +\usage{ +reduce_runs(x) +} +\arguments{ +\item{x}{\verb{} of character vectors} +} +\value{ +\verb{} of character vectors +} +\description{ +Reduce Runs +} +\examples{ +x <- random_hcpcs2(20) |> + split_lengths() |> + split_first() |> + process_groups() + +delist(x$g2) |> + stringr::str_split_fixed("", max_vlen(x$g2)) |> + as.data.frame() |> + purrr::map(uniq_narm) |> + purrr::map(sort_order) |> + purrr::map(reduce_runs) + +} diff --git a/man/sf_c.Rd b/man/sf_c.Rd new file mode 100644 index 0000000..373ad70 --- /dev/null +++ b/man/sf_c.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/stringfish.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{ +concatenated \verb{} vector +} +\description{ +Concatenate Vectors +} +\examples{ +sf_c(LETTERS, "A") + +} diff --git a/man/sf_convert.Rd b/man/sf_convert.Rd index 17699fb..1a2675d 100644 --- a/man/sf_convert.Rd +++ b/man/sf_convert.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/helpers.R +% Please edit documentation in R/stringfish.R \name{sf_convert} \alias{sf_convert} \title{Convert string to stringfish vector} @@ -16,6 +16,6 @@ sf_convert(x) Convert string to stringfish vector } \examples{ -sf_convert(random_hcpcs(500)) +sf_convert(random_hcpcs(50)) } diff --git a/man/sf_detect.Rd b/man/sf_detect.Rd index 721f158..eadc36d 100644 --- a/man/sf_detect.Rd +++ b/man/sf_detect.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/helpers.R +% Please edit documentation in R/stringfish.R \name{sf_detect} \alias{sf_detect} \title{Detect by Regex} diff --git a/man/sf_extract.Rd b/man/sf_extract.Rd index 5789202..de3bc52 100644 --- a/man/sf_extract.Rd +++ b/man/sf_extract.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/helpers.R +% Please edit documentation in R/stringfish.R \name{sf_extract} \alias{sf_extract} \title{Extract by Regex} diff --git a/man/sf_nchar.Rd b/man/sf_nchar.Rd index c0af359..5d4eabe 100644 --- a/man/sf_nchar.Rd +++ b/man/sf_nchar.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/helpers.R +% Please edit documentation in R/stringfish.R \name{sf_nchar} \alias{sf_nchar} \title{Count number of characters in character vector} diff --git a/man/sf_remove.Rd b/man/sf_remove.Rd index f298681..7340f75 100644 --- a/man/sf_remove.Rd +++ b/man/sf_remove.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/helpers.R +% Please edit documentation in R/stringfish.R \name{sf_remove} \alias{sf_remove} \title{Remove by Regex} diff --git a/man/sf_sub.Rd b/man/sf_sub.Rd index 98966ec..1850d7a 100644 --- a/man/sf_sub.Rd +++ b/man/sf_sub.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/helpers.R +% Please edit documentation in R/stringfish.R \name{sf_sub} \alias{sf_sub} \title{Subset Vector by Range} diff --git a/man/split_1.Rd b/man/split_1.Rd index 6245fc9..6ee2239 100644 --- a/man/split_1.Rd +++ b/man/split_1.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/helpers.R +% Please edit documentation in R/splitters.R \name{split_1} \alias{split_1} \title{Split Vector} diff --git a/man/split_at.Rd b/man/split_at.Rd index becc9b2..0e6e342 100644 --- a/man/split_at.Rd +++ b/man/split_at.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/helpers.R +% Please edit documentation in R/splitters.R \name{split_at} \alias{split_at} \title{Split Vector by Index Subset} diff --git a/man/split_end.Rd b/man/split_end.Rd index f5b9fea..5b47353 100644 --- a/man/split_end.Rd +++ b/man/split_end.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/split_lengths.R +% Please edit documentation in R/splitters.R \name{split_end} \alias{split_end} \title{Split Character Vector at End} diff --git a/man/split_first.Rd b/man/split_first.Rd index be2aef5..c2cd7fa 100644 --- a/man/split_first.Rd +++ b/man/split_first.Rd @@ -1,15 +1,13 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/split_lengths.R +% Please edit documentation in R/splitters.R \name{split_first} \alias{split_first} \title{Split Character Vector by Lengths} \usage{ -split_first(x, verbose = FALSE) +split_first(x) } \arguments{ \item{x}{\verb{} vector} - -\item{verbose}{\verb{} print output} } \value{ \verb{} of character vectors diff --git a/man/split_lengths.Rd b/man/split_lengths.Rd index f59d2cb..322d1ca 100644 --- a/man/split_lengths.Rd +++ b/man/split_lengths.Rd @@ -1,15 +1,13 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/split_lengths.R +% Please edit documentation in R/splitters.R \name{split_lengths} \alias{split_lengths} \title{Split Character Vector by Lengths} \usage{ -split_lengths(x, verbose = FALSE) +split_lengths(x) } \arguments{ \item{x}{\verb{} vector} - -\item{verbose}{\verb{} print output} } \value{ \verb{} of character vectors diff --git a/man/splits.Rd b/man/splits.Rd index ca4df19..bc382df 100644 --- a/man/splits.Rd +++ b/man/splits.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/helpers.R +% Please edit documentation in R/splitters.R \name{splits} \alias{splits} \title{Delist, Unname and Split a String} diff --git a/man/strsort.Rd b/man/strsort.Rd index 676fd6c..e8c350f 100644 --- a/man/strsort.Rd +++ b/man/strsort.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/helpers.R +% Please edit documentation in R/fastverse.R \name{strsort} \alias{strsort} \title{Parallel Sort wrapper using \code{\link[kit:psort]{kit::psort()}}} diff --git a/man/take_at.Rd b/man/take_at.Rd index 7988e2f..8519bae 100644 --- a/man/take_at.Rd +++ b/man/take_at.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/helpers.R +% Please edit documentation in R/stringfish.R \name{take_at} \alias{take_at} \title{Subset Vector at Index} diff --git a/man/uniq.Rd b/man/uniq.Rd new file mode 100644 index 0000000..2931e81 --- /dev/null +++ b/man/uniq.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/fastverse.R +\name{uniq} +\alias{uniq} +\title{Unique Values of Vector} +\usage{ +uniq(x) +} +\arguments{ +\item{x}{vector} +} +\value{ +vector +} +\description{ +Unique Values of Vector +} +\examples{ +random_hcpcs(5) |> uniq() + +} diff --git a/man/uniq_narm.Rd b/man/uniq_narm.Rd index 7673e90..ebaa87b 100644 --- a/man/uniq_narm.Rd +++ b/man/uniq_narm.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/helpers.R +% Please edit documentation in R/fastverse.R \name{uniq_narm} \alias{uniq_narm} \title{Unique Values with NAs Removed} diff --git a/man/uniq_vlen.Rd b/man/uniq_vlen.Rd index 6002294..37173d0 100644 --- a/man/uniq_vlen.Rd +++ b/man/uniq_vlen.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/helpers.R +% Please edit documentation in R/fastverse.R \name{uniq_vlen} \alias{uniq_vlen} \title{Unique Lengths of Vector} diff --git a/man/vlen.Rd b/man/vlen.Rd index 205eaab..2e6c059 100644 --- a/man/vlen.Rd +++ b/man/vlen.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/helpers.R +% Please edit documentation in R/fastverse.R \name{vlen} \alias{vlen} \title{Lengths of Vector}