Skip to content

Commit fa13761

Browse files
authored
Format with Air (#1591)
* Add `air.toml` * Format `data-raw/` * Format `R/` * Format `tests/` * Add missing `.Rbuildignore` entry * Reformat again with better hugging and `~` behavior * Reformat with tight `()` hugging
1 parent 3a9a93c commit fa13761

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1344
-684
lines changed

.Rbuildignore

+2
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@
2121
^\.github/workflows/R\.yaml$
2222
^\.github/workflows/pr-commands\.yaml$
2323
^CRAN-SUBMISSION$
24+
^air.toml$
25+
^\.vscode$

.vscode/settings.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"[r]": {
3+
"editor.formatOnSave": true
4+
}
5+
}

R/chop.R

+21-8
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,14 @@ col_chop <- function(x, indices) {
105105

106106
#' @export
107107
#' @rdname chop
108-
unchop <- function(data,
109-
cols,
110-
...,
111-
keep_empty = FALSE,
112-
ptype = NULL,
113-
error_call = current_env()) {
108+
unchop <- function(
109+
data,
110+
cols,
111+
...,
112+
keep_empty = FALSE,
113+
ptype = NULL,
114+
error_call = current_env()
115+
) {
114116
check_dots_empty0(...)
115117
check_data_frame(data, call = error_call)
116118
check_required(cols, call = error_call)
@@ -168,7 +170,13 @@ unchop <- function(data,
168170
# used to slice the data frame `x` was subset from to align it with `val`.
169171
# - `val` the unchopped data frame.
170172

171-
df_unchop <- function(x, ..., ptype = NULL, keep_empty = FALSE, error_call = caller_env()) {
173+
df_unchop <- function(
174+
x,
175+
...,
176+
ptype = NULL,
177+
keep_empty = FALSE,
178+
error_call = caller_env()
179+
) {
172180
check_dots_empty()
173181

174182
ptype <- check_list_of_ptypes(ptype, names = names(x), call = error_call)
@@ -271,7 +279,12 @@ df_unchop <- function(x, ..., ptype = NULL, keep_empty = FALSE, error_call = cal
271279
col <- unname(col)
272280

273281
row_recycle <- col_sizes != sizes
274-
col[row_recycle] <- map2(col[row_recycle], sizes[row_recycle], vec_recycle, call = error_call)
282+
col[row_recycle] <- map2(
283+
col[row_recycle],
284+
sizes[row_recycle],
285+
vec_recycle,
286+
call = error_call
287+
)
275288

276289
col <- list_unchop(
277290
x = col,

R/complete.R

+3-13
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,12 @@
6161
#' fill = list(value1 = 0, value2 = 99),
6262
#' explicit = FALSE
6363
#' )
64-
complete <- function(data,
65-
...,
66-
fill = list(),
67-
explicit = TRUE) {
68-
64+
complete <- function(data, ..., fill = list(), explicit = TRUE) {
6965
UseMethod("complete")
7066
}
7167

7268
#' @export
73-
complete.data.frame <- function(data,
74-
...,
75-
fill = list(),
76-
explicit = TRUE) {
69+
complete.data.frame <- function(data, ..., fill = list(), explicit = TRUE) {
7770
check_bool(explicit)
7871

7972
out <- expand(data, ...)
@@ -100,10 +93,7 @@ complete.data.frame <- function(data,
10093
}
10194

10295
#' @export
103-
complete.grouped_df <- function(data,
104-
...,
105-
fill = list(),
106-
explicit = TRUE) {
96+
complete.grouped_df <- function(data, ..., fill = list(), explicit = TRUE) {
10797
out <- dplyr::reframe(
10898
data,
10999
complete(

R/data.R

-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@
185185
#' (downloaded April 2008)
186186
"billboard"
187187

188-
189188
#' Household data
190189
#'
191190
#' This dataset is based on an example in

R/dep-extract.R

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
#' @keywords internal
99
#' @export
1010
extract_numeric <- function(x) {
11-
message("extract_numeric() is deprecated: please use readr::parse_number() instead")
11+
message(
12+
"extract_numeric() is deprecated: please use readr::parse_number() instead"
13+
)
1214
as.numeric(gsub("[^0-9.-]+", "", as.character(x)))
1315
}
1416

R/dep-lazyeval.R

+101-27
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,31 @@ nesting_ <- function(x) {
7979
#' @rdname deprecated-se
8080
#' @inheritParams extract
8181
#' @export
82-
extract_ <- function(data, col, into, regex = "([[:alnum:]]+)", remove = TRUE,
83-
convert = FALSE, ...) {
82+
extract_ <- function(
83+
data,
84+
col,
85+
into,
86+
regex = "([[:alnum:]]+)",
87+
remove = TRUE,
88+
convert = FALSE,
89+
...
90+
) {
8491
lifecycle::deprecate_warn("1.0.0", "extract_()", "extract()", always = TRUE)
8592
UseMethod("extract_")
8693
}
8794
#' @export
88-
extract_.data.frame <- function(data, col, into, regex = "([[:alnum:]]+)",
89-
remove = TRUE, convert = FALSE, ...) {
95+
extract_.data.frame <- function(
96+
data,
97+
col,
98+
into,
99+
regex = "([[:alnum:]]+)",
100+
remove = TRUE,
101+
convert = FALSE,
102+
...
103+
) {
90104
col <- compat_lazy(col, caller_env())
91-
extract(data,
105+
extract(
106+
data,
92107
col = !!col,
93108
into = into,
94109
regex = regex,
@@ -107,7 +122,11 @@ fill_ <- function(data, fill_cols, .direction = c("down", "up")) {
107122
UseMethod("fill_")
108123
}
109124
#' @export
110-
fill_.data.frame <- function(data, fill_cols, .direction = c("down", "up", "downup", "updown")) {
125+
fill_.data.frame <- function(
126+
data,
127+
fill_cols,
128+
.direction = c("down", "up", "downup", "updown")
129+
) {
111130
vars <- syms(fill_cols)
112131
fill(data, !!!vars, .direction = .direction)
113132
}
@@ -120,20 +139,34 @@ fill_.data.frame <- function(data, fill_cols, .direction = c("down", "up", "down
120139
#' pair of key-value columns.
121140
#' @keywords internal
122141
#' @export
123-
gather_ <- function(data, key_col, value_col, gather_cols, na.rm = FALSE,
124-
convert = FALSE, factor_key = FALSE) {
142+
gather_ <- function(
143+
data,
144+
key_col,
145+
value_col,
146+
gather_cols,
147+
na.rm = FALSE,
148+
convert = FALSE,
149+
factor_key = FALSE
150+
) {
125151
lifecycle::deprecate_warn("1.2.0", "gather_()", "gather()", always = TRUE)
126152
UseMethod("gather_")
127153
}
128154
#' @export
129-
gather_.data.frame <- function(data, key_col, value_col, gather_cols,
130-
na.rm = FALSE, convert = FALSE,
131-
factor_key = FALSE) {
155+
gather_.data.frame <- function(
156+
data,
157+
key_col,
158+
value_col,
159+
gather_cols,
160+
na.rm = FALSE,
161+
convert = FALSE,
162+
factor_key = FALSE
163+
) {
132164
key_col <- sym(key_col)
133165
value_col <- sym(value_col)
134166
gather_cols <- syms(gather_cols)
135167

136-
gather(data,
168+
gather(
169+
data,
137170
key = !!key_col,
138171
value = !!value_col,
139172
!!!gather_cols,
@@ -154,32 +187,58 @@ nest_ <- function(...) {
154187
#' @rdname deprecated-se
155188
#' @inheritParams separate_rows
156189
#' @export
157-
separate_rows_ <- function(data, cols, sep = "[^[:alnum:].]+",
158-
convert = FALSE) {
190+
separate_rows_ <- function(
191+
data,
192+
cols,
193+
sep = "[^[:alnum:].]+",
194+
convert = FALSE
195+
) {
159196
lifecycle::deprecate_warn("1.2.0", "separate_rows_()", "separate_rows()")
160197
UseMethod("separate_rows_")
161198
}
162199
#' @export
163-
separate_rows_.data.frame <- function(data, cols, sep = "[^[:alnum:].]+",
164-
convert = FALSE) {
200+
separate_rows_.data.frame <- function(
201+
data,
202+
cols,
203+
sep = "[^[:alnum:].]+",
204+
convert = FALSE
205+
) {
165206
cols <- syms(cols)
166207
separate_rows(data, !!!cols, sep = sep, convert = convert)
167208
}
168209

169210
#' @rdname deprecated-se
170211
#' @inheritParams separate
171212
#' @export
172-
separate_ <- function(data, col, into, sep = "[^[:alnum:]]+", remove = TRUE,
173-
convert = FALSE, extra = "warn", fill = "warn", ...) {
213+
separate_ <- function(
214+
data,
215+
col,
216+
into,
217+
sep = "[^[:alnum:]]+",
218+
remove = TRUE,
219+
convert = FALSE,
220+
extra = "warn",
221+
fill = "warn",
222+
...
223+
) {
174224
lifecycle::deprecate_warn("1.2.0", "separate_()", "separate()", always = TRUE)
175225
UseMethod("separate_")
176226
}
177227
#' @export
178-
separate_.data.frame <- function(data, col, into, sep = "[^[:alnum:]]+",
179-
remove = TRUE, convert = FALSE,
180-
extra = "warn", fill = "warn", ...) {
228+
separate_.data.frame <- function(
229+
data,
230+
col,
231+
into,
232+
sep = "[^[:alnum:]]+",
233+
remove = TRUE,
234+
convert = FALSE,
235+
extra = "warn",
236+
fill = "warn",
237+
...
238+
) {
181239
col <- sym(col)
182-
separate(data,
240+
separate(
241+
data,
183242
col = !!col,
184243
into = into,
185244
sep = sep,
@@ -194,18 +253,33 @@ separate_.data.frame <- function(data, col, into, sep = "[^[:alnum:]]+",
194253
#' @inheritParams spread
195254
#' @param key_col,value_col Strings giving names of key and value cols.
196255
#' @export
197-
spread_ <- function(data, key_col, value_col, fill = NA, convert = FALSE,
198-
drop = TRUE, sep = NULL) {
256+
spread_ <- function(
257+
data,
258+
key_col,
259+
value_col,
260+
fill = NA,
261+
convert = FALSE,
262+
drop = TRUE,
263+
sep = NULL
264+
) {
199265
lifecycle::deprecate_warn("1.2.0", "spread_()", "spread()", always = TRUE)
200266
UseMethod("spread_")
201267
}
202268
#' @export
203-
spread_.data.frame <- function(data, key_col, value_col, fill = NA,
204-
convert = FALSE, drop = TRUE, sep = NULL) {
269+
spread_.data.frame <- function(
270+
data,
271+
key_col,
272+
value_col,
273+
fill = NA,
274+
convert = FALSE,
275+
drop = TRUE,
276+
sep = NULL
277+
) {
205278
key_col <- sym(key_col)
206279
value_col <- sym(value_col)
207280

208-
spread(data,
281+
spread(
282+
data,
209283
key = !!key_col,
210284
value = !!value_col,
211285
fill = fill,

R/doc-params.R

-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@
8181
#' @name tidyr_data_masking
8282
NULL
8383

84-
8584
#' Argument type: tidy-select
8685
#'
8786
#' @description

R/drop-na.R

+5-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ drop_na.data.frame <- function(data, ...) {
3232
# Use all columns if no `...` are supplied
3333
cols <- data
3434
} else {
35-
vars <- tidyselect::eval_select(expr(c(!!!dots)), data, allow_rename = FALSE)
35+
vars <- tidyselect::eval_select(
36+
expr(c(!!!dots)),
37+
data,
38+
allow_rename = FALSE
39+
)
3640
cols <- data[vars]
3741
}
3842

R/expand.R

+5-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,11 @@ expand_grid <- function(..., .name_repair = "check_unique", .vary = "slowest") {
223223

224224
# Flattens unnamed data frames after grid expansion
225225
out <- tidyr_new_list(out)
226-
out <- df_list(!!!out, .name_repair = .name_repair, .error_call = current_env())
226+
out <- df_list(
227+
!!!out,
228+
.name_repair = .name_repair,
229+
.error_call = current_env()
230+
)
227231
out <- tibble::new_tibble(out, nrow = size)
228232

229233
out

R/extract.R

+25-5
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,28 @@
4343
#'
4444
#' # If no match, NA:
4545
#' df %>% extract(x, c("A", "B"), "([a-d]+)-([a-d]+)")
46-
extract <- function(data, col, into, regex = "([[:alnum:]]+)",
47-
remove = TRUE, convert = FALSE, ...) {
46+
extract <- function(
47+
data,
48+
col,
49+
into,
50+
regex = "([[:alnum:]]+)",
51+
remove = TRUE,
52+
convert = FALSE,
53+
...
54+
) {
4855
check_dots_used()
4956
UseMethod("extract")
5057
}
5158
#' @export
52-
extract.data.frame <- function(data, col, into, regex = "([[:alnum:]]+)",
53-
remove = TRUE, convert = FALSE, ...) {
59+
extract.data.frame <- function(
60+
data,
61+
col,
62+
into,
63+
regex = "([[:alnum:]]+)",
64+
remove = TRUE,
65+
convert = FALSE,
66+
...
67+
) {
5468
check_required(col)
5569

5670
var <- tidyselect::vars_pull(names(data), !!enquo(col))
@@ -61,7 +75,13 @@ extract.data.frame <- function(data, col, into, regex = "([[:alnum:]]+)",
6175
reconstruct_tibble(data, out, if (remove) var else chr())
6276
}
6377

64-
str_extract <- function(x, into, regex, convert = FALSE, error_call = caller_env()) {
78+
str_extract <- function(
79+
x,
80+
into,
81+
regex,
82+
convert = FALSE,
83+
error_call = caller_env()
84+
) {
6585
check_string(regex, call = error_call)
6686
check_not_stringr_pattern(regex, call = error_call)
6787
check_character(into, call = error_call)

0 commit comments

Comments
 (0)