-
Notifications
You must be signed in to change notification settings - Fork 2
/
helper-filter.R
50 lines (44 loc) · 1.53 KB
/
helper-filter.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#' Filters sites by artefacts.
#'
#' Removes sites that sites that have been marked by feature/artefact filter.
#'
#' @param filter vector of strings that contains artefact filter information.
#' @param artefacts vector of characters that correspond to feature/artefact filters to be filtered, default: NULL - Filter all.
#' @return vector of logical.
#' @examples
#' data(rdd)
#' sum(filter_artefact(rdd$filter, c("D")))
#' @export
filter_artefact <- function(filter, artefacts = NULL) {
if (is.null(artefacts)) {
artefacts <- c(paste0('\\', .EMPTY))
}
grepl(paste0(artefacts, collapse = "|"), filter)
}
#' Merge tibbles with columns holding logical values with AND to a vector.
#'
#' Each column holding values of logicals will be merged row-wise with AND.
#' @param d tibble with logical values
#' @return logical tibble with columns merged with AND.
#' @export
All <- function(d) {
Reduce("&", tidyr::as_tibble(d))
}
#' Merge tibbles with columns holding the sum of numeric values of a vector.
#'
#' Each column holding values of numbers will be summed row-wise.
#' @param d tibble with numeric values
#' @return numeric tibble with summed columns.
#' @export
Allnum <- function(d) {
Reduce("+", tidyr::as_tibble(d))
}
#' Merge tibbles with columns holding logical values with OR to a vector.
#'
#' Each column holding values of logicals will be merged row-wise with OR.
#' @param d tibble with logical values
#' @return logical tibble with columns merged with OR.
#' @export
Any <- function(d) {
Reduce("|", tidyr::as_tibble(d))
}