Skip to content

Commit b8a34f3

Browse files
authored
Merge pull request #1956 from olivroy/lint2
Fix some lints + update visual tests
2 parents c63042b + d46c53d commit b8a34f3

Some content is hidden

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

66 files changed

+863
-817
lines changed

R/cols_merge.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@ cols_merge <- function(
233233
# that `pattern` not be evaluated, for much the same reason as above.
234234

235235
# Get the columns supplied in `hide_columns` as a character vector
236-
suppressWarnings(
237-
hide_columns <-
236+
hide_columns <-
237+
suppressWarnings(
238238
resolve_cols_c(
239239
expr = {{ hide_columns }},
240240
data = data

R/cols_width.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ cols_width <- function(
129129
all(
130130
vapply(
131131
widths_list,
132-
FUN = function(width) rlang::is_formula(width),
132+
FUN = rlang::is_formula,
133133
FUN.VALUE = logical(1L)
134134
)
135135
)

R/dt_boxhead.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,19 @@ dt_boxhead_edit <- function(data, var, ...) {
9797
check_names_dt_boxhead_expr(expr = val_list)
9898

9999
check_vars_dt_boxhead(var = var, dt_boxhead = dt_boxhead)
100-
100+
101101
col_row_num <- which(dt_boxhead$var == var_name)
102-
102+
103103
if (is.list(dt_boxhead[[names(val_list)]])) {
104104
dt_boxhead[[col_row_num, names(val_list)]] <- unname(val_list)
105105
# Fixup md() in column_label column
106106
# if a problem occurs. (preserve "from_markdown" class)
107-
if ("column_label" %in% names(val_list) &&
107+
if ("column_label" %in% names(val_list) &&
108108
is.list(dt_boxhead$column_label[[col_row_num]])) {
109109
# Remove one level of nesting
110110
dt_boxhead$column_label[[col_row_num]] <- dt_boxhead$column_label[[col_row_num]][[1]]
111111
}
112-
112+
113113
} else {
114114
dt_boxhead[[col_row_num, names(val_list)]] <- unlist(val_list)
115115
}
@@ -224,8 +224,8 @@ dt_boxhead_get_vars <- function(data) {
224224
}
225225

226226
dt_boxhead_get_vars_default <- function(data) {
227-
df <- dt_boxhead_get(data = data)
228-
df$var[df$type == "default"]
227+
dat <- dt_boxhead_get(data = data)
228+
dat$var[dat$type == "default"]
229229
}
230230

231231
dt_boxhead_get_var_stub <- function(data) {

R/dt_groups_rows.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ dt_groups_rows_build <- function(data, context) {
7171
# values), build the `groups_rows` table
7272
for (i in seq_along(ordering)) {
7373

74-
if (!all(is.na(ordering[i]))) {
75-
rows_matched <- which(stub_df$group_id == ordering[i])
76-
} else {
74+
if (all(is.na(ordering[i]))) {
7775
rows_matched <- which(is.na(stub_df$group_id))
76+
} else {
77+
rows_matched <- which(stub_df$group_id == ordering[i])
7878
}
7979

8080
# If `rows_matched` is NA then go to next iteration

R/dt_summary.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ dt_summary_build <- function(data, context) {
336336

337337
fmt_expr_components <- fmt_expr_values
338338
names(fmt_expr_components) <- fmt_expr_names
339-
fmt_expr_components <- fmt_expr_components[fmt_expr_names != ""]
339+
fmt_expr_components <- fmt_expr_components[nzchar(fmt_expr_names)]
340340

341341
if ("rows" %in% names(fmt_expr_components)) {
342342

R/export.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ as_rtf <- function(
409409
incl_close = incl_close
410410
)
411411

412-
if (isTRUE(getOption('knitr.in.progress'))) {
412+
if (isTRUE(getOption("knitr.in.progress"))) {
413413
rtf_table <- knitr::raw_output(rtf_table)
414414
}
415415

@@ -499,7 +499,7 @@ as_word <- function(
499499
# Perform input object validation
500500
stop_if_not_gt_tbl(data = data)
501501

502-
caption_location <-
502+
caption_location <-
503503
rlang::arg_match0(
504504
caption_location,
505505
values = c("top", "bottom", "embed")

R/extract.R

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,19 @@
8686
#' value for `build_stage` then the entire build for the table body (i.e., up
8787
#' to and including the `"footnotes_attached"` stage) will be performed before
8888
#' returning the data frame.
89-
#'
89+
#'
9090
#' @param incl_hidden_cols *Should hidden columns be included?*
91-
#'
91+
#'
9292
#' `scalar<logical>` // *default:* `FALSE`
93-
#'
93+
#'
9494
#' Certain columns may be hidden from final display via [cols_hide()]. By
9595
#' default, those columns won't be part of the extracted data frame. However,
9696
#' we can choose to include them by using `incl_hidden_cols = TRUE`.
97-
#'
97+
#'
9898
#' @param incl_stub_cols *Should stub columns be included?*
99-
#'
99+
#'
100100
#' `scalar<logical>` // *default:* `TRUE`
101-
#'
101+
#'
102102
#' Any stub columns in the **gt** object (which may consist of a grouping
103103
#' column and a column for row labels) are included in the extracted data for
104104
#' clarity but clearly marked with the names `"::group_id::"` and
@@ -114,7 +114,7 @@
114114
#' `"html"` (the default), `"latex"`, `"rtf"`, or `"word"`.
115115
#'
116116
#' @return A data frame or tibble object containing the table body.
117-
#'
117+
#'
118118
#' @section Examples:
119119
#'
120120
#' Use a modified version of [`sp500`] the dataset to create a **gt** table with
@@ -135,36 +135,36 @@
135135
#' fmt_date(columns = date, date_style = "day_month_year") |>
136136
#' fmt_currency(columns = c(open, high, low, close)) |>
137137
#' cols_hide(columns = c(high, low))
138-
#'
138+
#'
139139
#' ```
140-
#'
140+
#'
141141
#' ```r
142142
#' gt_tbl
143143
#' ```
144-
#'
144+
#'
145145
#' \if{html}{\out{
146146
#' `r man_get_image_tag(file = "man_extract_body_1.png")`
147147
#' }}
148-
#'
148+
#'
149149
#' Using `extract_body()` on the **gt** object (`gt_tbl`) will provide us with
150150
#' a tibble that contains the fully built data cells for the `output` context
151151
#' (in this case, `"html"`).
152-
#'
152+
#'
153153
#' ```{r}
154154
#' extract_body(gt_tbl)
155155
#' ```
156-
#'
156+
#'
157157
#' To provide us with a better frame of reference, the grouping and row label
158158
#' values are provided as the first columns in the returned output. We could
159-
#' suppress those in the output by setting `incl_stub_cols = FALSE`.
160-
#'
159+
#' suppress those in the output by setting `incl_stub_cols = FALSE`.
160+
#'
161161
#' ```{r}
162162
#' extract_body(gt_tbl, incl_stub_cols = FALSE)
163163
#' ```
164-
#'
164+
#'
165165
#' The `high` and `low` columns were hidden via [`cols_hide()`] and so they
166166
#' won't be shown in the returned data unless we use `incl_hidden_cols = TRUE`.
167-
#'
167+
#'
168168
#' ```{r}
169169
#' extract_body(
170170
#' gt_tbl,
@@ -195,7 +195,7 @@ extract_body <- function(
195195

196196
# If `build_stage` is given a keyword value, check that value is valid
197197
if (!is.null(build_stage)) {
198-
198+
199199
rlang::arg_match0(
200200
build_stage,
201201
values = c(
@@ -211,15 +211,15 @@ extract_body <- function(
211211
output,
212212
values = c("html", "latex", "rtf", "word", "grid")
213213
)
214-
214+
215215
rlang::check_dots_empty()
216216

217-
# Generate vector of columns to include in output
217+
# Generate vector of columns to include in output
218218
if (isTRUE(incl_hidden_cols)) {
219219

220220
boxhead_df <- dt_boxhead_get(data = data)
221221

222-
included_cols <-
222+
included_cols <-
223223
boxhead_df$var[boxhead_df$type %in% c("default", "hidden")]
224224

225225
} else {
@@ -246,98 +246,98 @@ extract_body <- function(
246246
}
247247

248248
data <- dt_body_build(data = data)
249-
249+
250250
if (identical(build_stage, "init")) {
251-
252-
out_df <-
251+
252+
out_df <-
253253
assemble_body_extract(
254254
data = data,
255255
included_cols = included_cols,
256256
incl_stub_cols = incl_stub_cols,
257257
group_col = group_col,
258258
rowname_col = rowname_col
259259
)
260-
260+
261261
return(out_df)
262262
}
263263

264264
data <- render_formats(data = data, context = output)
265265

266266
if (identical(build_stage, "fmt_applied")) {
267-
268-
out_df <-
267+
268+
out_df <-
269269
assemble_body_extract(
270270
data = data,
271271
included_cols = included_cols,
272272
incl_stub_cols = incl_stub_cols,
273273
group_col = group_col,
274274
rowname_col = rowname_col
275275
)
276-
276+
277277
return(out_df)
278278
}
279279

280280
data <- render_substitutions(data = data, context = output)
281281

282282
if (identical(build_stage, "sub_applied")) {
283-
284-
out_df <-
283+
284+
out_df <-
285285
assemble_body_extract(
286286
data = data,
287287
included_cols = included_cols,
288288
incl_stub_cols = incl_stub_cols,
289289
group_col = group_col,
290290
rowname_col = rowname_col
291291
)
292-
292+
293293
return(out_df)
294294
}
295295

296296
data <- migrate_unformatted_to_output(data = data, context = output)
297297

298298
if (identical(build_stage, "unfmt_included")) {
299-
300-
out_df <-
299+
300+
out_df <-
301301
assemble_body_extract(
302302
data = data,
303303
included_cols = included_cols,
304304
incl_stub_cols = incl_stub_cols,
305305
group_col = group_col,
306306
rowname_col = rowname_col
307307
)
308-
308+
309309
return(out_df)
310310
}
311311

312312
data <- perform_col_merge(data = data, context = output)
313313

314314
if (identical(build_stage, "cols_merged")) {
315-
316-
out_df <-
315+
316+
out_df <-
317317
assemble_body_extract(
318318
data = data,
319319
included_cols = included_cols,
320320
incl_stub_cols = incl_stub_cols,
321321
group_col = group_col,
322322
rowname_col = rowname_col
323323
)
324-
324+
325325
return(out_df)
326326
}
327327

328328
data <- dt_body_reassemble(data = data)
329329

330330
if (identical(build_stage, "body_reassembled")) {
331-
332-
out_df <-
331+
332+
out_df <-
333333
assemble_body_extract(
334334
data = data,
335335
included_cols = included_cols,
336336
incl_stub_cols = incl_stub_cols,
337337
group_col = group_col,
338338
rowname_col = rowname_col
339339
)
340-
340+
341341
return(out_df)
342342
}
343343

@@ -349,15 +349,15 @@ extract_body <- function(
349349

350350
if (identical(build_stage, "text_transformed")) {
351351

352-
out_df <-
352+
out_df <-
353353
assemble_body_extract(
354354
data = data,
355355
included_cols = included_cols,
356356
incl_stub_cols = incl_stub_cols,
357357
group_col = group_col,
358358
rowname_col = rowname_col
359359
)
360-
360+
361361
return(out_df)
362362
}
363363

@@ -372,9 +372,9 @@ extract_body <- function(
372372
data <- resolve_footnotes_styles(data = data, tbl_type = "footnotes")
373373
data <- apply_footnotes_to_output(data = data, context = output)
374374

375-
if (is.null(build_stage) || identical(build_stage, "footnotes_attached")) {
376-
377-
out_df <-
375+
if (is.null(build_stage) || identical(build_stage, "footnotes_attached")) {
376+
377+
out_df <-
378378
assemble_body_extract(
379379
data = data,
380380
included_cols = included_cols,
@@ -394,21 +394,21 @@ assemble_body_extract <- function(
394394
group_col,
395395
rowname_col
396396
) {
397-
397+
398398
out_df <- data[["_body"]][, included_cols]
399-
399+
400400
if (isTRUE(incl_stub_cols)) {
401-
401+
402402
if (!is.null(group_col)) {
403403
names(out_df)[names(out_df) == group_col] <- "::group_id::"
404404
}
405-
405+
406406
if (!is.null(rowname_col)) {
407407
# ::rowname::
408408
names(out_df)[names(out_df) == rowname_col] <- rowname_col_private
409409
}
410410
}
411-
411+
412412
out_df
413413
}
414414

@@ -618,7 +618,7 @@ extract_cells <- function(
618618
stop_if_not_gt_tbl(data = data)
619619

620620
# Ensure that `output` is matched correctly to one option
621-
output <-
621+
output <-
622622
rlang::arg_match0(
623623
output,
624624
values = c("auto", "plain", "html", "latex", "rtf", "word", "grid")

0 commit comments

Comments
 (0)