Skip to content

Commit

Permalink
added groupers and reducers
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewallenbruce committed Nov 12, 2024
1 parent 22677c3 commit 46c9f4d
Show file tree
Hide file tree
Showing 46 changed files with 1,183 additions and 576 deletions.
2 changes: 2 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ Imports:
cheapr,
collapse,
data.table,
dplyr,
glue,
kit,
purrr,
rlang,
stringfish,
stringi,
stringr,
vctrs
Suggests:
Expand Down
17 changes: 16 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -37,6 +44,7 @@ export(split_lengths)
export(splits)
export(strsort)
export(take_at)
export(uniq)
export(uniq_narm)
export(uniq_vlen)
export(vlen)
Expand All @@ -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)
135 changes: 135 additions & 0 deletions R/fastverse.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#' If Else wrapper using [kit::iif()]
#'
#' @param x `<logical>` 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 `<character>` 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 `<logical>` vector
#'
#' @examples
#' c(NA, "AA") |> not_na()
#'
#' @autoglobal
#'
#' @export
not_na <- \(x) !cheapr::is_na(x)

#' Get named element from list
#'
#' @param l named `<list>`
#'
#' @param nm `<character>` element name; can be a regex pattern
#'
#' @returns named `<list>` 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 `<integer>` 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 `<integer>` 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 `<integer>` vector
#'
#' @examples
#' random_hcpcs(5) |> max_vlen()
#'
#' @autoglobal
#'
#' @export
max_vlen <- \(x) collapse::fmax(vlen(x))
39 changes: 39 additions & 0 deletions R/generated-globals.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,62 @@

utils::globalVariables(c(
# <group_3>
# <group_4>
# <group_5>
"a1",
# <group_3>
# <group_4>
# <group_5>
"a2",
# <group_3>
# <group_4>
# <group_5>
"a3",
# <group_4>
# <group_5>
"a4",
# <group_5>
"a5",
# <group_3>
# <group_4>
# <group_5>
"code",
# <group_3>
# <group_4>
# <group_5>
"G",
# <reduce_runs>
"group",
# <group_4>
"grp1",
# <group_5>
"grp2",
# <group_3>
# <group_4>
# <group_5>
"i1",
# <group_3>
# <group_4>
# <group_5>
"i2",
# <group_3>
# <group_4>
# <group_5>
"i3",
# <group_4>
# <group_5>
"i4",
# <group_5>
"i5",
# <reduce_runs>
"keys",
# <group_3>
# <group_4>
# <group_5>
# <reduce_runs>
"N",
# <reduce_runs>
"value",
# <remove_redundant>
# <split_first>
"x1",
Expand Down
Loading

0 comments on commit 46c9f4d

Please sign in to comment.