Skip to content

Commit 6f25289

Browse files
committed
style with styler (and a few manual tweaks), CC @hadley
1 parent 6320d77 commit 6f25289

23 files changed

+196
-110
lines changed

R/check-names.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ check_names_before_after.character <- function(j, names) {
7676
check_needs_no_dim(j)
7777

7878
pos <- safe_match(j, names)
79-
if(anyNA(pos)) {
79+
if (anyNA(pos)) {
8080
unknown_names <- j[is.na(pos)]
8181
stopc(pluralise_msg("Column(s) ", unknown_names), " not found")
8282
}

R/compat-lazyeval.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ compat_lazy <- function(lazy, env = caller_env(), warn = TRUE) {
2424
return(quo())
2525
}
2626

27-
coerce_type(lazy, "quosure",
27+
coerce_type(
28+
lazy, "quosure",
2829
formula = as_quosure(lazy, env),
2930
symbol = ,
3031
language = new_quosure(lazy, env),
@@ -43,7 +44,8 @@ compat_lazy <- function(lazy, env = caller_env(), warn = TRUE) {
4344
new_quosure(lazy, env)
4445
},
4546
list =
46-
coerce_class(lazy, "quosure",
47+
coerce_class(
48+
lazy, "quosure",
4749
lazy = new_quosure(lazy$expr, lazy$env)
4850
)
4951
)

R/glimpse.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ glimpse.default <- function(x, width = NULL, max.level = 3, ...) {
7171
str_trunc <- function(x, max_width) {
7272
width <- nchar(x)
7373

74-
for(i in seq_along(x)) {
74+
for (i in seq_along(x)) {
7575
if (width[i] <= max_width[i]) next
7676

7777
x[i] <- paste0(substr(x[i], 1, max_width[i] - 3), "...")

R/rownames.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ rownames_to_column <- function(df, var = "rowname") {
5656
stopc("Column `", var, "` already exists")
5757
}
5858

59-
new_df <- add_column(df, !!(var) := rownames(df), .before = 1)
59+
new_df <- add_column(df, !! (var) := rownames(df), .before = 1)
6060
new_df
6161
}
6262

@@ -69,7 +69,7 @@ rowid_to_column <- function(df, var = "rowid") {
6969
stopc("Column `", var, "` already exists")
7070
}
7171

72-
new_df <- add_column(df, !!(var) := seq_len(nrow(df)), .before = 1)
72+
new_df <- add_column(df, !! (var) := seq_len(nrow(df)), .before = 1)
7373
new_df
7474
}
7575

R/tbl-df.r

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ print.tbl_df <- print.tbl
3333

3434
#' @export
3535
`[[.tbl_df` <- function(x, i, j, ..., exact = TRUE) {
36-
if (missing(j))
36+
if (missing(j)) {
3737
colname <- i
38-
else
38+
} else {
3939
colname <- j
40+
}
4041
if (!exact) {
4142
warningc("exact ignored")
4243
}

R/tibble.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,3 @@ invalid_df_msg <- function(problem, df, vars, extra) {
156156
pluralise_msg(problem, extra)
157157
)
158158
}
159-

R/tribble.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ extract_frame_names_from_dots <- function(dots) {
110110
}
111111

112112
validate_rectangular_shape <- function(frame_names, frame_rest) {
113-
if (length(frame_names) == 0 && length(frame_rest) == 0) return();
113+
if (length(frame_names) == 0 && length(frame_rest) == 0) return()
114114

115115
# Figure out the associated number of rows and number of columns,
116116
# and validate that the supplied formula produces a rectangular

R/type-sum.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ dim_desc <- function(x) {
2626
size_sum <- function(x) {
2727
if (!is_vector_s3(x)) return("")
2828

29-
paste0(" [", dim_desc(x), "]" )
29+
paste0(" [", dim_desc(x), "]")
3030
}
3131

3232
#' @importFrom pillar obj_sum

R/utils-format.r

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ format.trunc_mat <- function(x, width = NULL, ...) {
113113
# Needs to be defined in package code: r-lib/pkgload#85
114114
print_without_body <- function(x, ...) {
115115
mockr::with_mock(
116-
format_body = function(x, ...) { paste0("<body of ", length(format(x)), " row(s) created by pillar>") },
116+
format_body = function(x, ...) {
117+
paste0("<body of ", length(format(x)), " row(s) created by pillar>")
118+
},
117119
print(x, ...)
118120
)
119121
}
@@ -229,7 +231,7 @@ knit_print.trunc_mat <- function(x, options) {
229231
extra <- "\n"
230232
}
231233

232-
res <- paste(c('', '', summary, '', kable, '', extra), collapse = '\n')
234+
res <- paste(c("", "", summary, "", kable, "", extra), collapse = "\n")
233235
knitr::asis_output(res, cacheable = TRUE)
234236
}
235237

@@ -240,7 +242,9 @@ format_knitr_body <- function(x) {
240242
# Needs to be defined in package code: r-lib/pkgload#85
241243
knit_print_without_body <- function(x, ...) {
242244
mockr::with_mock(
243-
format_knitr_body = function(x, ...) { paste0("<body of ", length(knitr::knit_print(x)), " row(s) created by pillar>") },
245+
format_knitr_body = function(x, ...) {
246+
paste0("<body of ", length(knitr::knit_print(x)), " row(s) created by pillar>")
247+
},
244248
knitr::knit_print(x, ...)
245249
)
246250
}

R/wrap.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ col_strwrap <- function(x, width, indent, exdent) {
3232
)
3333
wrapped_dots_string <- paste(wrapped_dots, collapse = "\n")
3434

35-
space <- strsplit(wrapped_dots_string, "[.]+",)[[1L]]
35+
space <- strsplit(wrapped_dots_string, "[.]+")[[1L]]
3636
wrapped_styled_string <- paste0(c("", words), c(space, ""), collapse = "")
3737
strsplit(wrapped_styled_string, "\n", fixed = TRUE)[[1L]]
3838
}

tests/testthat/helper-data.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ df_all <- tibble(
1212
)
1313

1414
# An empty data frame with all major types
15-
df_empty = tibble(
15+
df_empty <- tibble(
1616
a = integer(0),
1717
b = double(0),
1818
c = logical(0),

tests/testthat/helper-output.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
output_file <- function(filename) file.path("output", filename)
22

33
expect_output_file_rel <- function(x, filename) {
4-
withr::with_options(list(digits = 4, width = 80),
4+
withr::with_options(
5+
list(digits = 4, width = 80),
56
expect_output_file(x, output_file(filename), update = TRUE)
67
)
78
}

tests/testthat/test-add.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@ test_that("can recycle when adding rows", {
6464
iris_new <- add_row(iris, Sepal.Length = -1:-2, Species = "unknown")
6565
expect_identical(nrow(iris_new), nrow(iris) + 2L)
6666
expect_identical(iris_new$Sepal.Length, c(iris$Sepal.Length, -1:-2))
67-
expect_identical(as.character(iris_new$Species),
68-
c(as.character(iris$Species), "unknown", "unknown"))
67+
expect_identical(
68+
as.character(iris_new$Species),
69+
c(as.character(iris$Species), "unknown", "unknown")
70+
)
6971
})
7072

7173
test_that("can add as first row via .before = 1", {

tests/testthat/test-data-frame.R

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ test_that("length 1 vectors are recycled", {
6060
tibble(x = 1:10, y = 1:2),
6161
"Column `y` must be length 1 or 10, not 2",
6262
fixed = TRUE
63-
6463
)
6564
})
6665

@@ -95,7 +94,7 @@ test_that("names in list columns are preserved", {
9594

9695
test_that("attributes are preserved", {
9796
df <- structure(
98-
data.frame( x = 1:10, g1 = rep(1:2, each = 5), g2 = rep(1:5, 2) ),
97+
data.frame(x = 1:10, g1 = rep(1:2, each = 5), g2 = rep(1:5, 2)),
9998
meta = "this is important"
10099
)
101100
res <- as_tibble(df)
@@ -179,15 +178,19 @@ test_that("NULL makes 0 x 0 tbl_df", {
179178

180179
test_that("as_tibble.tbl_df() leaves classes unchanged (#60)", {
181180
df <- tibble()
182-
expect_equal(class(df),
183-
c("tbl_df", "tbl", "data.frame"))
184-
expect_equal(class(structure(df, class = c("my_df", class(df)))),
185-
c("my_df", "tbl_df", "tbl", "data.frame"))
181+
expect_equal(
182+
class(df),
183+
c("tbl_df", "tbl", "data.frame")
184+
)
185+
expect_equal(
186+
class(structure(df, class = c("my_df", class(df)))),
187+
c("my_df", "tbl_df", "tbl", "data.frame")
188+
)
186189
})
187190

188191

189192
test_that("Can convert tables to data frame", {
190-
mtcars_table <- xtabs(mtcars, formula = ~vs+am+cyl)
193+
mtcars_table <- xtabs(mtcars, formula = ~vs + am + cyl)
191194

192195
mtcars_tbl <- as_tibble(mtcars_table)
193196
expect_equal(names(mtcars_tbl), c(names(dimnames(mtcars_table)), "n"))

tests/testthat/test-enframe.R

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,42 @@ context("enframe")
44
# enframe -----------------------------------------------------------------
55

66
test_that("can convert unnamed vector", {
7-
expect_identical(enframe(3:1),
8-
tibble(name = 1:3, value = 3:1))
7+
expect_identical(
8+
enframe(3:1),
9+
tibble(name = 1:3, value = 3:1)
10+
)
911
})
1012

1113
test_that("can convert named vector", {
12-
expect_identical(enframe(c(a = 2, b = 1)),
13-
tibble(name = letters[1:2], value = as.numeric(2:1)))
14+
expect_identical(
15+
enframe(c(a = 2, b = 1)),
16+
tibble(name = letters[1:2], value = as.numeric(2:1))
17+
)
1418
})
1519

1620
test_that("can convert zero-length vector", {
17-
expect_identical(enframe(logical()),
18-
tibble(name = integer(), value = logical()))
21+
expect_identical(
22+
enframe(logical()),
23+
tibble(name = integer(), value = logical())
24+
)
1925
})
2026

2127
test_that("can use custom names", {
22-
expect_identical(enframe(letters, name = "index", value = "letter"),
23-
tibble(index = seq_along(letters),
24-
letter = letters))
28+
expect_identical(
29+
enframe(letters, name = "index", value = "letter"),
30+
tibble(
31+
index = seq_along(letters),
32+
letter = letters
33+
)
34+
)
2535
})
2636

2737

2838
# deframe -----------------------------------------------------------------
2939

3040
test_that("can deframe two-column data frame", {
31-
expect_identical(deframe(tibble(name = letters[1:3], value = 3:1)),
32-
c(a = 3L, b = 2L, c = 1L))
41+
expect_identical(
42+
deframe(tibble(name = letters[1:3], value = 3:1)),
43+
c(a = 3L, b = 2L, c = 1L)
44+
)
3345
})

tests/testthat/test-glimpse.R

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,41 +31,49 @@ test_that("format_v for list", {
3131
test_that("glimpse output matches known output", {
3232
expect_output_file_rel(
3333
glimpse(as_tibble(mtcars), width = 70L),
34-
"glimpse/mtcars-70.txt")
34+
"glimpse/mtcars-70.txt"
35+
)
3536

3637
expect_output_file_rel(
3738
glimpse(as_tibble(iris), width = 70L),
38-
"glimpse/iris-70.txt")
39+
"glimpse/iris-70.txt"
40+
)
3941

4042
expect_output_file_rel(
4143
glimpse(as_tibble(iris[integer()]), width = 70L),
42-
"glimpse/iris-empty-70.txt")
44+
"glimpse/iris-empty-70.txt"
45+
)
4346

4447
expect_output_file_rel(
4548
glimpse(tibble("mean(x)" = 5, "var(x)" = 3), width = 28),
46-
"glimpse/non-syntactic.txt")
49+
"glimpse/non-syntactic.txt"
50+
)
4751

4852
expect_output_file_rel(
4953
glimpse(as_tibble(df_all), width = 70L),
50-
"glimpse/all-70.txt")
54+
"glimpse/all-70.txt"
55+
)
5156

5257
withr::with_options(
5358
list(tibble.width = 50),
5459
expect_output_file_rel(
5560
glimpse(as_tibble(df_all)),
56-
"glimpse/all-50.txt")
61+
"glimpse/all-50.txt"
62+
)
5763
)
5864

5965
withr::with_options(
6066
list(tibble.width = 35),
6167
expect_output_file_rel(
6268
glimpse(as_tibble(df_all)),
63-
"glimpse/all-35.txt")
69+
"glimpse/all-35.txt"
70+
)
6471
)
6572

6673
expect_output_file_rel(
6774
glimpse(5),
68-
"glimpse/5.txt")
75+
"glimpse/5.txt"
76+
)
6977
})
7078

7179
test_that("glimpse(width = Inf) raises legible error", {

tests/testthat/test-has-name.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ test_that("other types", {
1111
})
1212

1313
test_that("vectorized", {
14-
expect_equal(has_name(list(a = 1), letters ), c(TRUE, rep(FALSE, 25)))
14+
expect_equal(has_name(list(a = 1), letters), c(TRUE, rep(FALSE, 25)))
1515
})
1616

1717
test_that("NA", {

tests/testthat/test-lst.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ context("lst")
33
test_that("lst handles named and unnamed NULL arguments", {
44
expect_equivalent(lst(NULL), list("NULL" = NULL))
55
expect_identical(lst(a = NULL), list(a = NULL))
6-
expect_identical(lst(NULL, b = NULL, 1:3),
7-
list("NULL" = NULL, b = NULL, "1:3" = 1:3))
6+
expect_identical(
7+
lst(NULL, b = NULL, 1:3),
8+
list("NULL" = NULL, b = NULL, "1:3" = 1:3)
9+
)
810
})
911

1012
test_that("lst handles internal references", {

tests/testthat/test-matrix.R

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ test_that("properly handles poly class (#110)", {
3939
p_df <- as_tibble(p)
4040

4141
expect_equal(names(p_df), colnames(p))
42-
expect_equal(class(p_df[[1L]]), class(p[,1]))
42+
expect_equal(class(p_df[[1L]]), class(p[, 1]))
4343
})
4444

4545
test_that("handles atomic vectors", {
@@ -65,13 +65,16 @@ test_that("handles atomic vectors", {
6565
})
6666

6767
test_that("auto-assigning names", {
68-
expect_identical(as_tibble(diag(3L)),
69-
as_tibble(as.data.frame(diag(3L))))
68+
expect_identical(
69+
as_tibble(diag(3L)),
70+
as_tibble(as.data.frame(diag(3L)))
71+
)
7072
})
7173

7274
test_that("forwarding to as.data.frame() for ts objects (#184)", {
7375
mts <- cbind(
7476
A = ts(c(1, 1, 2, 2), start = 2016, freq = 4),
75-
B = ts(c(11, 11, 12, 13), start = 2016, freq = 4))
77+
B = ts(c(11, 11, 12, 13), start = 2016, freq = 4)
78+
)
7679
expect_identical(as_tibble(mts), as_tibble(as.data.frame(mts)))
7780
})

0 commit comments

Comments
 (0)