-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathwidth.R
42 lines (37 loc) · 861 Bytes
/
width.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
get_width <- function(x) {
attr(x, "width", exact = TRUE)
}
# Set width and minimum width information for an object
#
# Returns the input with updated `width` or `min_width` attributes.
#
# @param x Input to which assign a width or minimum width
# @param width,min_width The new width
set_width <- function(x, width) {
if (is.null(width)) {
return(x)
}
if (is.infinite(width)) {
attr(x, "width") <- NA_integer_
} else {
attr(x, "width") <- as.integer(width)
}
x
}
get_widths <- function(x) {
map_int(x, get_width)
}
get_min_width <- function(x) {
attr(x, "min_width", exact = TRUE) %||% get_width(x)
}
# @rdname set_width
set_min_width <- function(x, min_width) {
if (is.null(min_width)) {
return(x)
}
attr(x, "min_width") <- as.integer(min_width)
x
}
get_min_widths <- function(x) {
map_int(x, get_min_width)
}