|
5 | 5 | #' multiple inputs at once. They work similarly to how [pmin()] and [pmax()] are |
6 | 6 | #' parallel variants of [min()] and [max()]. |
7 | 7 | #' |
8 | | -#' @inheritParams rlang::args_dots_empty |
9 | 8 | #' @inheritParams rlang::args_error_context |
10 | 9 | #' |
11 | | -#' @param x A list of logical vectors of equal size. |
| 10 | +#' @param ... Logical vectors of equal size. |
12 | 11 | #' |
13 | | -#' @param missing Handling of missing values. One of: |
| 12 | +#' @param .missing Handling of missing values. One of: |
14 | 13 | #' |
15 | 14 | #' - `NULL`, no special behavior is applied. Missings are treated the same way |
16 | 15 | #' as `|` or `&`. |
|
19 | 18 | #' |
20 | 19 | #' - `TRUE` to treat missing values as `TRUE`. |
21 | 20 | #' |
22 | | -#' @param size An optional output size. Only useful to specify if `x` could be |
23 | | -#' an empty list. |
| 21 | +#' @param .size An optional output size. Only useful to specify if it is possible |
| 22 | +#' for no inputs to be provided. |
24 | 23 | #' |
25 | | -#' @param x_arg Argument name used in error messages. |
| 24 | +#' @param .arg Argument name used in error messages. |
26 | 25 | #' |
27 | | -#' @returns A logical vector the same size as the vectors in `x`. |
| 26 | +#' @returns A logical vector the same size as the vectors in `...`. |
28 | 27 | #' |
29 | 28 | #' @details |
30 | | -#' `list_pany()` and `list_pall()` are consistent with [any()] and [all()] when |
| 29 | +#' `vec_pany()` and `vec_pall()` are consistent with [any()] and [all()] when |
31 | 30 | #' there are no inputs to process in parallel: |
32 | 31 | #' |
33 | | -#' - `any()` returns `FALSE` with no inputs. Similarly, |
34 | | -#' `list_pany(list(), size = 1)` returns `FALSE`. |
| 32 | +#' - `any()` returns `FALSE` with no inputs. Similarly, `vec_pany(.size = 1)` |
| 33 | +#' returns `FALSE`. |
35 | 34 | #' |
36 | | -#' - `all()` returns `TRUE` with no inputs. Similarly, |
37 | | -#' `list_pall(list(), size = 1)` returns `TRUE`. |
| 35 | +#' - `all()` returns `TRUE` with no inputs. Similarly, `vec_pall(.size = 1)` |
| 36 | +#' returns `TRUE`. |
38 | 37 | #' |
39 | 38 | #' @name parallel-operators |
40 | 39 | #' |
41 | 40 | #' @examples |
42 | 41 | #' a <- c(TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, NA, NA, NA) |
43 | 42 | #' b <- c(TRUE, FALSE, NA, TRUE, FALSE, NA, TRUE, FALSE, NA) |
44 | | -#' x <- list(a, b) |
45 | 43 | #' |
46 | 44 | #' # Default behavior treats missings like `|` does |
47 | | -#' list_pany(x) |
| 45 | +#' vec_pany(a, b) |
48 | 46 | #' a | b |
49 | 47 | #' |
50 | 48 | #' # Default behavior treats missings like `&` does |
51 | | -#' list_pall(x) |
| 49 | +#' vec_pall(a, b) |
52 | 50 | #' a & b |
53 | 51 | #' |
54 | 52 | #' # Remove missings from the computation, like `na_rm = TRUE` |
55 | | -#' list_pany(x, missing = FALSE) |
| 53 | +#' vec_pany(a, b, .missing = FALSE) |
56 | 54 | #' (a & !is.na(a)) | (b & !is.na(b)) |
57 | 55 | #' |
58 | | -#' list_pall(x, missing = TRUE) |
| 56 | +#' vec_pall(a, b, .missing = TRUE) |
59 | 57 | #' (a | is.na(a)) & (b | is.na(b)) |
60 | 58 | #' |
61 | | -#' # `list_pall()` can be used to implement a `dplyr::filter()` style API |
| 59 | +#' # `vec_pall()` can be used to implement a `dplyr::filter()` style API |
62 | 60 | #' df <- data_frame(id = seq_along(a), a = a, b = b) |
63 | 61 | #' |
64 | 62 | #' keep_rows <- function(x, ...) { |
65 | | -#' vec_slice(x, list_pall(list(...), missing = FALSE)) |
| 63 | +#' vec_slice(x, vec_pall(..., .missing = FALSE)) |
66 | 64 | #' } |
67 | 65 | #' drop_rows <- function(x, ...) { |
68 | | -#' vec_slice(x, !list_pall(list(...), missing = FALSE)) |
| 66 | +#' vec_slice(x, !vec_pall(..., .missing = FALSE)) |
69 | 67 | #' } |
70 | 68 | #' |
71 | 69 | #' # "Keep / Drop the rows when both a and b are TRUE" |
|
74 | 72 | #' drop_rows(df, a, b) |
75 | 73 | #' |
76 | 74 | #' # Same empty behavior as `any()` and `all()` |
77 | | -#' list_pany(list(), size = 1) |
| 75 | +#' vec_pany(.size = 1) |
78 | 76 | #' any() |
79 | 77 | #' |
80 | | -#' list_pall(list(), size = 1) |
| 78 | +#' vec_pall(.size = 1) |
81 | 79 | #' all() |
82 | 80 | NULL |
83 | 81 |
|
84 | 82 | #' @rdname parallel-operators |
85 | 83 | #' @export |
86 | | -list_pany <- function( |
87 | | - x, |
| 84 | +vec_pany <- function( |
88 | 85 | ..., |
89 | | - missing = NULL, |
90 | | - size = NULL, |
91 | | - x_arg = caller_arg(x), |
92 | | - error_call = current_env() |
| 86 | + .missing = NULL, |
| 87 | + .size = NULL, |
| 88 | + .arg = "", |
| 89 | + .error_call = current_env() |
93 | 90 | ) { |
94 | | - check_dots_empty0(...) |
95 | | - .Call(ffi_list_pany, x, missing, size, environment()) |
| 91 | + .Call(ffi_vec_pany, list2(...), .missing, .size, environment()) |
96 | 92 | } |
97 | 93 |
|
98 | 94 | #' @rdname parallel-operators |
99 | 95 | #' @export |
100 | | -list_pall <- function( |
101 | | - x, |
| 96 | +vec_pall <- function( |
102 | 97 | ..., |
103 | | - missing = NULL, |
104 | | - size = NULL, |
105 | | - x_arg = caller_arg(x), |
106 | | - error_call = current_env() |
| 98 | + .missing = NULL, |
| 99 | + .size = NULL, |
| 100 | + .arg = "", |
| 101 | + .error_call = current_env() |
107 | 102 | ) { |
108 | | - check_dots_empty0(...) |
109 | | - .Call(ffi_list_pall, x, missing, size, environment()) |
| 103 | + .Call(ffi_vec_pall, list2(...), .missing, .size, environment()) |
110 | 104 | } |
0 commit comments