Skip to content

Commit 79f7766

Browse files
committed
Merge branch 'r-1.1.0.9000' into production
2 parents b9dc799 + 149e459 commit 79f7766

File tree

9 files changed

+66
-15
lines changed

9 files changed

+66
-15
lines changed

API

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,23 @@ as.blob(x, ...)
66
blob(...)
77
new_blob(x)
88

9-
## S3 methods
9+
## Foreign S3 methods
1010

11+
[.blob(x, i, ...)
12+
[<-.blob(x, i, ..., value)
13+
[[<-.blob(x, i, ..., value)
1114
as.blob.blob(x, ...)
1215
as.blob.character(x, ...)
1316
as.blob.integer(x, ...)
1417
as.blob.list(x, ...)
1518
as.blob.raw(x, ...)
19+
as.data.frame.blob(x, row.names = NULL, optional = FALSE, ..., nm = paste(deparse(substitute(x), width.cutoff = 500L), collapse = " "))
20+
c.blob(x, ...)
21+
format.blob(x, ...)
22+
is.na.blob(x)
23+
is.na<-.blob(x, value)
24+
is_vector_s3.blob(x)
25+
obj_sum.blob(x)
26+
pillar_shaft.blob(x, ...)
27+
print.blob(x, ...)
28+
type_sum.blob(x)

DESCRIPTION

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
Package: blob
22
Title: A Simple S3 Class for Representing Vectors of Binary Data ('BLOBS')
3-
Version: 1.1.0
3+
Version: 1.1.0.9000
44
Authors@R: c(
55
person("Hadley", "Wickham", role = c("aut")),
66
person("Kirill", "Müller", , "krlmlr+r@mailbox.org", role = c("cre")),
77
person("RStudio", role = "cph")
88
)
99
Description: R's raw vector is useful for storing a single binary object.
10-
What if you want to put a vector of them in a data frame? The blob
10+
What if you want to put a vector of them in a data frame? The 'blob'
1111
package provides the blob object, a list of raw vectors, suitable for
1212
use as a column in data frame.
1313
Imports:
14-
tibble
14+
methods,
15+
pillar
1516
License: GPL-3
1617
Encoding: UTF-8
1718
LazyData: true

NAMESPACE

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,19 @@ S3method(as.blob,integer)
1010
S3method(as.blob,list)
1111
S3method(as.blob,raw)
1212
S3method(as.data.frame,blob)
13+
S3method(c,blob)
1314
S3method(format,blob)
1415
S3method(is.na,blob)
1516
S3method(is_vector_s3,blob)
1617
S3method(obj_sum,blob)
18+
S3method(pillar_shaft,blob)
1719
S3method(print,blob)
1820
S3method(type_sum,blob)
1921
export(as.blob)
2022
export(blob)
2123
export(new_blob)
22-
importFrom(tibble,is_vector_s3)
23-
importFrom(tibble,obj_sum)
24-
importFrom(tibble,type_sum)
24+
importFrom(methods,setOldClass)
25+
importFrom(pillar,is_vector_s3)
26+
importFrom(pillar,obj_sum)
27+
importFrom(pillar,pillar_shaft)
28+
importFrom(pillar,type_sum)

NEWS.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
### blob 1.1.0.9000 (2017-11-29)
2+
3+
- Use `B` instead of `b` as unit.
4+
- Now importing pillar instead of tibble, and using colored formatting.
5+
- The blob class can now be used for S4 dispatch.
6+
- Calling `c()` on blob objects returns a blob.
7+
8+
19
# blob 1.1.0 (2017-06-17)
210

311
- New maintainer: Kirill Müller.

R/accessors.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@
2525
NextMethod()
2626
}
2727
}
28+
29+
#' @export
30+
c.blob <- function(x, ...) as.blob(NextMethod())

R/blob.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#' @importFrom methods setOldClass
2+
setOldClass("blob")
3+
14
#' Construct a blob object
25
#'
36
#' \code{new_blob} is a low-level constructor that takes a list of

R/format.R

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ format.blob <- function(x, ...) {
33
if (length(x) == 0)
44
return(character())
55

6-
ifelse(is.na(x), "<NA>", paste0("blob[", blob_size(x, ...) , "]"))
6+
ifelse(is.na(x), "<NA>", paste0("blob[", blob_size(x, ...), "]"))
77
}
88

99
#' @export
@@ -16,25 +16,25 @@ print.blob <- function(x, ...) {
1616
}
1717

1818
#' @export
19-
#' @importFrom tibble type_sum
19+
#' @importFrom pillar type_sum
2020
type_sum.blob <- function(x) {
2121
"blob"
2222
}
2323

2424
#' @export
25-
#' @importFrom tibble obj_sum
25+
#' @importFrom pillar obj_sum
2626
obj_sum.blob <- function(x) {
2727
format(x, trim = FALSE)
2828
}
2929

3030
#' @export
31-
#' @importFrom tibble is_vector_s3
31+
#' @importFrom pillar is_vector_s3
3232
is_vector_s3.blob <- function(x) TRUE
3333

3434
blob_size <- function(x, digits = 3, trim = TRUE, ...) {
3535
x <- vapply(x, length, numeric(1))
3636

37-
units <- c("kb", "Mb", "Gb", "Tb")
37+
units <- c("kB", "MB", "GB", "TB")
3838
power <- min(floor(log(abs(x), 1000)), length(units))
3939
if (power < 1) {
4040
unit <- "B"
@@ -47,3 +47,15 @@ blob_size <- function(x, digits = 3, trim = TRUE, ...) {
4747
x2 <- format(x1, big.mark = ",", scientific = FALSE, trim = trim)
4848
paste0(x2, " ", unit)
4949
}
50+
51+
#' @importFrom pillar pillar_shaft
52+
#' @export
53+
pillar_shaft.blob <- function(x, ...) {
54+
out <- ifelse(
55+
is.na(x),
56+
NA_character_,
57+
paste0(pillar::style_subtle("["), blob_size(x, ...), pillar::style_subtle("]"))
58+
)
59+
60+
pillar::new_pillar_shaft_simple(out, align = "right")
61+
}

tests/testthat/test-accessors.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,10 @@ test_that("can insert raw or NULL", {
2222

2323
expect_equal(x, blob(as.raw(0), as.raw(0), NULL, NULL))
2424
})
25+
26+
test_that("can combine", {
27+
expect_identical(
28+
c(blob(raw(4), raw(5)), blob(raw(7))),
29+
blob(raw(4), raw(5), raw(7))
30+
)
31+
})

tests/testthat/test-format.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ test_that("similar sizes", {
3535
expect_format_equal(
3636
format(x),
3737
c(
38-
"blob[1 kb]",
39-
"blob[2 kb]",
40-
"blob[4 kb]"
38+
"blob[1 kB]",
39+
"blob[2 kB]",
40+
"blob[4 kB]"
4141
)
4242
)
4343
})

0 commit comments

Comments
 (0)