Skip to content

Commit 378b24d

Browse files
committed
Format package w/ air
1 parent e79aa09 commit 378b24d

File tree

7 files changed

+63
-28
lines changed

7 files changed

+63
-28
lines changed

R/cast.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ vec_cast.blob.vctrs_list_of <- function(x, to, ...) {
3131
#' @method vec_cast.blob integer
3232
#' @export
3333
vec_cast.blob.integer <- function(x, to, ...) {
34-
signal_soft_deprecated("Coercing an integer vector to a blob is deprecated, please coerce to a list first.")
34+
signal_soft_deprecated(
35+
"Coercing an integer vector to a blob is deprecated, please coerce to a list first."
36+
)
3537
blob(!!!lapply(x, as_single_raw))
3638
}
3739

R/coerce.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
#' @method vec_ptype2 blob
88
#' @export
99
#' @export vec_ptype2.blob
10-
vec_ptype2.blob <- function(x, y, ..., x_arg = "", y_arg = "") UseMethod("vec_ptype2.blob", y)
10+
vec_ptype2.blob <- function(x, y, ..., x_arg = "", y_arg = "") {
11+
UseMethod("vec_ptype2.blob", y)
12+
}
1113

1214
#' @method vec_ptype2.blob default
1315
#' @export

R/compat-lifecycle.R

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#
2626
# - Soft-namespaced private objects.
2727

28-
2928
#' Signal deprecation
3029
#'
3130
#' @description
@@ -99,18 +98,23 @@ signal_soft_deprecated <- function(msg, id = msg, env = rlang::caller_env(2)) {
9998
rlang::is_reference(topenv(env), rlang::global_env())
10099
}
101100

102-
if (rlang::is_true(rlang::peek_option("lifecycle_verbose_soft_deprecation")) ||
103-
env_inherits_global(env)) {
101+
if (
102+
rlang::is_true(rlang::peek_option("lifecycle_verbose_soft_deprecation")) ||
103+
env_inherits_global(env)
104+
) {
104105
warn_deprecated(msg, id)
105106
return(invisible(NULL))
106107
}
107108

108109
# Test for environment names rather than reference/contents because
109110
# testthat clones the namespace
110111
tested_package <- Sys.getenv("TESTTHAT_PKG")
111-
if (nzchar(tested_package) &&
112-
identical(Sys.getenv("NOT_CRAN"), "true") &&
113-
rlang::env_name(topenv(env)) == rlang::env_name(rlang::ns_env(tested_package))) {
112+
if (
113+
nzchar(tested_package) &&
114+
identical(Sys.getenv("NOT_CRAN"), "true") &&
115+
rlang::env_name(topenv(env)) ==
116+
rlang::env_name(rlang::ns_env(tested_package))
117+
) {
114118
warn_deprecated(msg, id)
115119
return(invisible(NULL))
116120
}
@@ -126,12 +130,14 @@ warn_deprecated <- function(msg, id = msg) {
126130
return(invisible(NULL))
127131
}
128132

129-
if (!rlang::is_true(rlang::peek_option("lifecycle_repeat_warnings")) &&
130-
rlang::env_has(.rlang_lifecycle_deprecation_env, id)) {
133+
if (
134+
!rlang::is_true(rlang::peek_option("lifecycle_repeat_warnings")) &&
135+
rlang::env_has(.rlang_lifecycle_deprecation_env, id)
136+
) {
131137
return(invisible(NULL))
132138
}
133139

134-
rlang::env_poke(.rlang_lifecycle_deprecation_env, id, TRUE);
140+
rlang::env_poke(.rlang_lifecycle_deprecation_env, id, TRUE)
135141

136142
has_colour <- function() rlang::is_installed("crayon") && crayon::has_color()
137143
silver <- function(x) if (has_colour()) crayon::silver(x) else x
@@ -143,7 +149,11 @@ warn_deprecated <- function(msg, id = msg) {
143149
}
144150

145151
if (!rlang::is_true(rlang::peek_option("lifecycle_repeat_warnings"))) {
146-
msg <- paste0(msg, "\n", silver("This warning is displayed once per session."))
152+
msg <- paste0(
153+
msg,
154+
"\n",
155+
silver("This warning is displayed once per session.")
156+
)
147157
}
148158

149159
.Signal(msg = msg)
@@ -163,17 +173,16 @@ stop_defunct <- function(msg) {
163173
}
164174

165175
local_lifecycle_silence <- function(frame = rlang::caller_env()) {
166-
rlang::local_options(.frame = frame,
167-
lifecycle_disable_warnings = TRUE
168-
)
176+
rlang::local_options(.frame = frame, lifecycle_disable_warnings = TRUE)
169177
}
170178
with_lifecycle_silence <- function(expr) {
171179
local_lifecycle_silence()
172180
expr
173181
}
174182

175183
local_lifecycle_warnings <- function(frame = rlang::caller_env()) {
176-
rlang::local_options(.frame = frame,
184+
rlang::local_options(
185+
.frame = frame,
177186
lifecycle_disable_warnings = FALSE,
178187
lifecycle_verbose_soft_deprecation = TRUE,
179188
lifecycle_repeat_warnings = TRUE
@@ -186,9 +195,7 @@ with_lifecycle_warnings <- function(expr) {
186195

187196
local_lifecycle_errors <- function(frame = rlang::caller_env()) {
188197
local_lifecycle_warnings(frame = frame)
189-
rlang::local_options(.frame = frame,
190-
lifecycle_warnings_as_errors = TRUE
191-
)
198+
rlang::local_options(.frame = frame, lifecycle_warnings_as_errors = TRUE)
192199
}
193200
with_lifecycle_errors <- function(expr) {
194201
local_lifecycle_errors()

R/format.R

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
#' @export
22
format.blob <- function(x, ...) {
3-
if (length(x) == 0)
3+
if (length(x) == 0) {
44
return(character())
5+
}
56

67
ifelse(is.na(x), "<NA>", paste0("blob[", blob_size(x, ...), "]"))
78
}
89

910
#' @export
1011
obj_print_data.blob <- function(x, ...) {
11-
if (length(x) == 0)
12+
if (length(x) == 0) {
1213
return()
14+
}
1315

1416
out <- stats::setNames(format(x), names(x))
1517
print(out, quote = FALSE)
@@ -41,7 +43,11 @@ pillar_shaft.blob <- function(x, ...) {
4143
out <- ifelse(
4244
is.na(x),
4345
NA_character_,
44-
paste0(pillar::style_subtle("<raw "), blob_size(x, ...), pillar::style_subtle(">"))
46+
paste0(
47+
pillar::style_subtle("<raw "),
48+
blob_size(x, ...),
49+
pillar::style_subtle(">")
50+
)
4551
)
4652

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

R/util.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
is_raw_list <- function(x) {
2-
if (!is.list(x))
2+
if (!is.list(x)) {
33
return(FALSE)
4+
}
45

56
raw <- vapply(x, is.raw, logical(1))
67
null <- vapply(x, is.null, logical(1))
78

8-
if (!all(raw | null))
9+
if (!all(raw | null)) {
910
return(FALSE)
11+
}
1012

1113
TRUE
1214
}

tests/testthat/test-accessors.R

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,18 @@ test_that("subset assignment works", {
2424
test_that("can't insert objects of incorrect type", {
2525
x <- blob(!!!as.raw(1:5))
2626

27-
expect_error(x[[1]] <- 1, regexp = "Can't convert `value` <double> to <raw>", class = "vctrs_error_incompatible", fixed = TRUE)
28-
expect_error(x[1] <- 1, regexp = "Can't convert `X[[i]]` <double> to <raw>", class = "vctrs_error_incompatible", fixed = TRUE)
27+
expect_error(
28+
x[[1]] <- 1,
29+
regexp = "Can't convert `value` <double> to <raw>",
30+
class = "vctrs_error_incompatible",
31+
fixed = TRUE
32+
)
33+
expect_error(
34+
x[1] <- 1,
35+
regexp = "Can't convert `X[[i]]` <double> to <raw>",
36+
class = "vctrs_error_incompatible",
37+
fixed = TRUE
38+
)
2939
})
3040

3141
test_that("can insert raw or NULL", {

tests/testthat/test-cast.R

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,21 @@ test_that("casting with as.blob()", {
88
expect_identical(as.blob(list(raw(1))), blob(raw(1)))
99
expect_identical(as.blob(raw(1)), blob(raw(1)))
1010
expect_identical(as.blob(1:3), blob(as.raw(1), as.raw(2), as.raw(3)))
11-
expect_identical(as.blob(c("abc", "def")), blob(charToRaw("abc"), charToRaw("def")))
11+
expect_identical(
12+
as.blob(c("abc", "def")),
13+
blob(charToRaw("abc"), charToRaw("def"))
14+
)
1215
})
1316

1417
test_that("casting with as_blob()", {
1518
expect_identical(as_blob(blob(raw(1))), blob(raw(1)))
1619
expect_identical(as_blob(list(raw(1))), blob(raw(1)))
1720
expect_identical(as_blob(raw(1)), blob(raw(1)))
1821
expect_identical(blob(!!!as.raw(1:3)), blob(as.raw(1), as.raw(2), as.raw(3)))
19-
expect_identical(as_blob(c("abc", "def")), blob(charToRaw("abc"), charToRaw("def")))
22+
expect_identical(
23+
as_blob(c("abc", "def")),
24+
blob(charToRaw("abc"), charToRaw("def"))
25+
)
2026
})
2127

2228
test_that("NA_character_ is converted to missing blob()", {

0 commit comments

Comments
 (0)