-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathvctr.R
78 lines (66 loc) · 1.75 KB
/
vctr.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#' @export
pillar_shaft.pillar_vctr <- function(x, ...) {
# still seems necessary
pillar_shaft(unclass(x))
}
#' @export
vec_ptype_full.pillar_vctr <- function(x, ...) {
format(attr(x, "pillar", exact = TRUE))
}
#' @export
print.pillar_vctr <- function(x, ..., max = NULL) {
if (is.null(max)) {
max <- getOption("max.print")
}
xx <- vec_head(x, max)
size <- vec_size(x)
obj_print_header.pillar_vctr(xx, ..., .size = size)
obj_print_data.pillar_vctr(xx, ..., .size = size)
obj_print_footer.pillar_vctr(xx, ..., .size = size)
invisible(x)
}
#' @export
obj_print_header.pillar_vctr <- function(x, ..., .size) {
writeLines(paste0("<", vec_ptype_full(x), "[", .size, "]>"))
pillar_attr <- attr(x, "pillar")
if (!is.null(pillar_attr$fixed_exponent)) {
shaft <- pillar_shaft_number_attr(numeric(), pillar_attr)
type <- attr(shaft, "type")
if (!is.null(type)) {
writeLines(paste0("Fixed exponent: ", type[[1]]))
}
}
invisible(x)
}
#' @export
obj_print_data.pillar_vctr <- function(x, ..., .size) {
if (length(x) == 0) {
return(invisible(x))
}
# FIXME: base::print.default() can't use color, roll own implementation?
out <- stats::setNames(ansi_strip(format(x)), names(x))
print(out, quote = FALSE, max = vec_size(x))
invisible(x)
}
#' @export
obj_print_footer.pillar_vctr <- function(x, ..., .size) {
delta <- .size - vec_size(x)
if (delta <= 0) {
return(invisible(x))
}
writeLines(style_subtle(pre_dots(paste0("and ", delta, " more"))))
invisible(x)
}
#' @export
print.pillar_vctr_attr <- function(x, ...) {
writeLines(format(x))
invisible(x)
}
#' @export
vec_proxy_compare.pillar_vctr <- function(x, ...) {
vec_data(x)
}
#' @export
vec_proxy_order.pillar_vctr <- function(x, ...) {
vec_data(x)
}