-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
22677c3
commit 46c9f4d
Showing
46 changed files
with
1,183 additions
and
576 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.