-
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
2687b50
commit 858106b
Showing
6 changed files
with
163 additions
and
8 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
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,95 @@ | ||
#' @name matchAll | ||
#' @inherit AcidGenerics::matchAll | ||
#' | ||
#' @note Updated 2023-12-15. | ||
#' | ||
#' @inheritParams AcidRoxygen::params | ||
#' @param ... Additional arguments. | ||
#' | ||
#' @param simplify `logical(1)`. | ||
#' Unlist match list into a positional vector. | ||
#' | ||
#' @examples | ||
#' ## vector ==== | ||
#' x <- c("c", "b", "a") | ||
#' table <- c("a", "b", "c", "a", "b", "c") | ||
#' i <- matchAll(x = x, table = table, simplify = FALSE) | ||
#' print(i) | ||
#' i <- matchAll(x = x, table = table, simplify = TRUE) | ||
#' print(i) | ||
NULL | ||
|
||
|
||
|
||
## Updated 2023-12-15. | ||
`matchAll,vector` <- # nolint | ||
function(x, table, simplify = FALSE) { | ||
assert( | ||
hasLength(x), | ||
hasNoDuplicates(x), | ||
hasLength(table), | ||
isFlag(simplify) | ||
) | ||
out <- lapply( | ||
X = x, | ||
FUN = function(x, table) { | ||
lgl <- table %in% x | ||
assert( | ||
any(lgl), | ||
msg = sprintf("Failed to match {.var %s}.", x) | ||
) | ||
which(lgl) | ||
}, | ||
table = table | ||
) | ||
if (isTRUE(simplify)) { | ||
out <- unlist(x = out, recursive = FALSE, use.names = FALSE) | ||
} | ||
out | ||
} | ||
|
||
|
||
|
||
`matchAll,character` <- # nolint | ||
`matchAll,vector` | ||
|
||
`matchAll,factor` <- # nolint | ||
`matchAll,vector` | ||
|
||
`matchAll,numeric` <- # nolint | ||
`matchAll,vector` | ||
|
||
|
||
|
||
#' @rdname matchAll | ||
#' @export | ||
setMethod( | ||
f = "matchAll", | ||
signature = signature( | ||
x = "character", | ||
table = "character" | ||
), | ||
definition = `matchAll,character` | ||
) | ||
|
||
#' @rdname matchAll | ||
#' @export | ||
setMethod( | ||
f = "matchAll", | ||
signature = signature( | ||
x = "factor", | ||
table = "factor" | ||
), | ||
definition = `matchAll,factor` | ||
) | ||
|
||
#' @rdname matchAll | ||
#' @export | ||
setMethod( | ||
f = "matchAll", | ||
signature = signature( | ||
x = "numeric", | ||
table = "numeric" | ||
), | ||
definition = `matchAll,numeric` | ||
) |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.