Skip to content

Commit

Permalink
Add matchAll methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mjsteinbaugh committed Dec 15, 2023
1 parent 2687b50 commit 858106b
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 8 deletions.
14 changes: 7 additions & 7 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: AcidBase
Title: Acid Genomics Base Functions
Description: Low-level base functions imported by Acid Genomics packages.
Version: 0.7.3.9000
Date: 2023-12-12
Date: 2023-12-15
Authors@R: c(
person(
"Michael", "Steinbaugh",
Expand All @@ -22,17 +22,17 @@ License: AGPL-3
Encoding: UTF-8
Depends: R (>= 4.3)
Imports:
AcidGenerics (>= 0.7.3),
BiocGenerics (>= 0.46.0),
S4Vectors (>= 0.38.0),
goalie (>= 0.7.5),
AcidGenerics (>= 0.7.6),
BiocGenerics (>= 0.48.0),
S4Vectors (>= 0.40.0),
goalie (>= 0.7.7),
methods
Suggests:
AcidCLI (>= 0.3.0),
AcidTest (>= 0.9.0),
memuse (>= 4.2.3),
processx (>= 3.8.2),
testthat (>= 3.2.0),
processx (>= 3.8.3),
testthat (>= 3.2.1),
withr (>= 2.5.2),
parallel,
stats,
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export(lanePattern)
export(logRatioToFoldChange)
export(majorMinorVersion)
export(majorVersion)
export(matchAll)
export(matchNested)
export(metadataDenylist)
export(methodFormals)
Expand Down Expand Up @@ -80,6 +81,7 @@ exportMethods(headtail)
exportMethods(intersectionMatrix)
exportMethods(keepOnlyAtomicCols)
exportMethods(logRatioToFoldChange)
exportMethods(matchAll)
exportMethods(matchNested)
exportMethods(rankedMatrix)
exportMethods(sem)
Expand All @@ -97,6 +99,7 @@ importFrom(AcidGenerics,intersectAll)
importFrom(AcidGenerics,intersectionMatrix)
importFrom(AcidGenerics,keepOnlyAtomicCols)
importFrom(AcidGenerics,logRatioToFoldChange)
importFrom(AcidGenerics,matchAll)
importFrom(AcidGenerics,matchNested)
importFrom(AcidGenerics,rankedMatrix)
importFrom(AcidGenerics,sem)
Expand Down
6 changes: 6 additions & 0 deletions R/AllGenerics.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ NULL
#' @usage logRatioToFoldChange(object, ...)
NULL

#' @rdname matchAll
#' @name matchAll
#' @export
#' @usage matchAll(x, table, ...)
NULL

#' @rdname matchNested
#' @name matchNested
#' @export
Expand Down
95 changes: 95 additions & 0 deletions R/matchAll-methods.R
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`
)
2 changes: 1 addition & 1 deletion R/package.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ NULL

#' @importFrom AcidGenerics coerceToList euclidean foldChangeToLogRatio
#' geometricMean headtail intersectAll intersectionMatrix keepOnlyAtomicCols
#' logRatioToFoldChange matchNested rankedMatrix sem showHeader zscore
#' logRatioToFoldChange matchAll matchNested rankedMatrix sem showHeader zscore
#' @importFrom BiocGenerics dims do.call duplicated grep grepl match unlist
#' unique unlist
#' @importFrom S4Vectors head metadata metadata<- na.omit tail
Expand Down
51 changes: 51 additions & 0 deletions man/matchAll.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 858106b

Please sign in to comment.