-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathutils.R
More file actions
39 lines (34 loc) · 730 Bytes
/
utils.R
File metadata and controls
39 lines (34 loc) · 730 Bytes
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
#' Pipe operator
#'
#' @name %>%
#' @rdname pipe
#' @keywords internal
#' @export
#' @importFrom magrittr %>%
#' @usage lhs \%>\% rhs
NULL
reduce_common <- function(x, msg = "Objects must be identical",
operator = identical) {
reduce(x, function(.x, .y) {
if (!operator(.x, .y)) {
stop(msg, call. = FALSE)
}
.y
})
}
has_name <- function(x) {
nms <- names(x)
if (is.null(nms)) {
rep(FALSE, length(x))
} else {
!(is.na(nms) | nms == "")
}
}
big_mark <- function(x, ...) {
mark <- if (identical(getOption("OutDec"), ",")) "." else ","
formatC(x, big.mark = mark, ...)
}
id <- function(n) {
width <- nchar(n)
sprintf(paste0("%0", width, "d"), seq_len(n))
}