Skip to content

Commit d77c35f

Browse files
committed
prettyunits and angle brackets
- Now using the prettyunits package to format data sizes.
1 parent 72e3007 commit d77c35f

File tree

2 files changed

+4
-15
lines changed

2 files changed

+4
-15
lines changed

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ Description: R's raw vector is useful for storing a single binary object.
1212
use as a column in data frame.
1313
Imports:
1414
methods,
15-
pillar
15+
pillar,
16+
prettyunits
1617
License: GPL-3
1718
Encoding: UTF-8
1819
LazyData: true

R/format.R

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,7 @@ is_vector_s3.blob <- function(x) TRUE
3333

3434
blob_size <- function(x, digits = 3, trim = TRUE, ...) {
3535
x <- vapply(x, length, numeric(1))
36-
37-
units <- c("kB", "MB", "GB", "TB")
38-
power <- min(floor(log(abs(x), 1000)), length(units))
39-
if (power < 1) {
40-
unit <- "B"
41-
} else {
42-
unit <- units[[power]]
43-
x <- x / (1024 ^ power)
44-
}
45-
46-
x1 <- signif(x, digits = digits %||% 3)
47-
x2 <- format(x1, big.mark = ",", scientific = FALSE, trim = trim)
48-
paste0(x2, " ", unit)
36+
prettyunits::pretty_bytes(x)
4937
}
5038

5139
#' @importFrom pillar pillar_shaft
@@ -54,7 +42,7 @@ pillar_shaft.blob <- function(x, ...) {
5442
out <- ifelse(
5543
is.na(x),
5644
NA_character_,
57-
paste0(pillar::style_subtle("["), blob_size(x, ...), pillar::style_subtle("]"))
45+
paste0(pillar::style_subtle("<raw "), blob_size(x, ...), pillar::style_subtle(">"))
5846
)
5947

6048
pillar::new_pillar_shaft_simple(out, align = "right")

0 commit comments

Comments
 (0)