| 1 |
get_width <- function(x) { |
| 2 |
attr(x, "width", exact = TRUE) |
| 3 |
} |
| 4 |
|
| 5 |
# Set width and minimum width information for an object |
| 6 |
# |
| 7 |
# Returns the input with updated `width` or `min_width` attributes. |
| 8 |
# |
| 9 |
# @param x Input to which assign a width or minimum width |
| 10 |
# @param width,min_width The new width |
| 11 |
set_width <- function(x, width) { |
| 12 |
if (is.null(width)) { |
| 13 |
return(x) |
| 14 |
} |
| 15 |
if (is.infinite(width)) { |
| 16 |
attr(x, "width") <- NA_integer_ |
| 17 |
} else { |
| 18 |
attr(x, "width") <- as.integer(width) |
| 19 |
} |
| 20 |
x |
| 21 |
} |
| 22 |
|
| 23 |
get_widths <- function(x) { |
| 24 |
map_int(x, get_width) |
| 25 |
} |
| 26 |
|
| 27 |
get_min_width <- function(x) { |
| 28 |
attr(x, "min_width", exact = TRUE) %||% get_width(x) |
| 29 |
} |
| 30 |
|
| 31 |
# @rdname set_width |
| 32 |
set_min_width <- function(x, min_width) { |
| 33 |
if (is.null(min_width)) { |
| 34 |
return(x) |
| 35 |
} |
| 36 |
attr(x, "min_width") <- as.integer(min_width) |
| 37 |
x |
| 38 |
} |
| 39 |
|
| 40 |
get_min_widths <- function(x) { |
| 41 |
map_int(x, get_min_width) |
| 42 |
} |