Skip to content

Commit 7cbf430

Browse files
authored
Format with Air (#629)
* Air setup * Format `R/` * Format `inst/` * Format `tests/` * Set the `defaultFormatter`
1 parent ebcc762 commit 7cbf430

33 files changed

+839
-451
lines changed

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@
1717
^appveyor\.yml$
1818
^internal$
1919
^CRAN-SUBMISSION$
20+
^air.toml$

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"[r]": {
3+
"editor.formatOnSave": true,
4+
"editor.defaultFormatter": "Posit.air-vscode"
5+
}
6+
}

R/bq-auth.R

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
## The roxygen comments for these functions are mostly generated from data
88
## in this list and template text maintained in gargle.
99
gargle_lookup_table <- list(
10-
PACKAGE = "bigrquery",
11-
YOUR_STUFF = "your BigQuery projects",
12-
PRODUCT = "Google BigQuery",
13-
API = "BigQuery API",
14-
PREFIX = "bq"
10+
PACKAGE = "bigrquery",
11+
YOUR_STUFF = "your BigQuery projects",
12+
PRODUCT = "Google BigQuery",
13+
API = "BigQuery API",
14+
PREFIX = "bq"
1515
)
1616

1717
#' Authorize bigrquery
@@ -48,15 +48,17 @@ gargle_lookup_table <- list(
4848
#' }
4949
#'
5050
#' @importFrom gargle token_fetch
51-
bq_auth <- function(email = gargle::gargle_oauth_email(),
52-
path = NULL,
53-
scopes = c(
54-
"https://www.googleapis.com/auth/bigquery",
55-
"https://www.googleapis.com/auth/cloud-platform"
56-
),
57-
cache = gargle::gargle_oauth_cache(),
58-
use_oob = gargle::gargle_oob_default(),
59-
token = NULL) {
51+
bq_auth <- function(
52+
email = gargle::gargle_oauth_email(),
53+
path = NULL,
54+
scopes = c(
55+
"https://www.googleapis.com/auth/bigquery",
56+
"https://www.googleapis.com/auth/cloud-platform"
57+
),
58+
cache = gargle::gargle_oauth_cache(),
59+
use_oob = gargle::gargle_oob_default(),
60+
token = NULL
61+
) {
6062
if (!missing(email) && !missing(path)) {
6163
cli::cli_warn(c(
6264
"It is very unusual to provide both {.arg email} and \\
@@ -249,8 +251,9 @@ bq_user <- function() {
249251
#' @export
250252
bq_oauth_app <- function() {
251253
lifecycle::deprecate_warn(
252-
"1.4.2", "bq_oauth_app()", "bq_oauth_client()"
254+
"1.4.2",
255+
"bq_oauth_app()",
256+
"bq_oauth_client()"
253257
)
254258
bq_oauth_client()
255259
}
256-

R/bq-dataset.R

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,13 @@ bq_dataset_delete <- function(x, delete_contents = FALSE) {
9595

9696
#' @export
9797
#' @rdname api-dataset
98-
bq_dataset_tables <- function(x, page_size = 50, max_pages = Inf, warn = TRUE, ...) {
98+
bq_dataset_tables <- function(
99+
x,
100+
page_size = 50,
101+
max_pages = Inf,
102+
warn = TRUE,
103+
...
104+
) {
99105
x <- as_bq_dataset(x)
100106
url <- bq_path(x$project, x$dataset, "")
101107

R/bq-download.R

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,18 @@
7373
#' @examplesIf bq_testable()
7474
#' df <- bq_table_download("publicdata.samples.natality", n_max = 35000, billing = bq_test_project())
7575
bq_table_download <-
76-
function(x,
77-
n_max = Inf,
78-
page_size = NULL,
79-
start_index = 0L,
80-
max_connections = 6L,
81-
quiet = NA,
82-
bigint = c("integer", "integer64", "numeric", "character"),
83-
api = c("json", "arrow"),
84-
billing = x$project,
85-
max_results = deprecated()) {
76+
function(
77+
x,
78+
n_max = Inf,
79+
page_size = NULL,
80+
start_index = 0L,
81+
max_connections = 6L,
82+
quiet = NA,
83+
bigint = c("integer", "integer64", "numeric", "character"),
84+
api = c("json", "arrow"),
85+
billing = x$project,
86+
max_results = deprecated()
87+
) {
8688
x <- as_bq_table(x)
8789
check_number_whole(n_max, min = 0, allow_infinite = TRUE)
8890
check_number_whole(start_index, min = 0)
@@ -93,13 +95,18 @@ bq_table_download <-
9395

9496
if (lifecycle::is_present(max_results)) {
9597
lifecycle::deprecate_warn(
96-
"1.4.0", "bq_table_download(max_results)", "bq_table_download(n_max)"
98+
"1.4.0",
99+
"bq_table_download(max_results)",
100+
"bq_table_download(n_max)"
97101
)
98102
n_max <- max_results
99103
}
100104

101105
if (api == "arrow") {
102-
check_installed("bigrquerystorage", "required to download using arrow API")
106+
check_installed(
107+
"bigrquerystorage",
108+
"required to download using arrow API"
109+
)
103110
if (!missing(page_size)) {
104111
cli::cli_warn(
105112
'{.arg page_size} is ignored when {.code api == "arrow"}',
@@ -264,7 +271,6 @@ check_api <- function(api = c("json", "arrow"), error_call = caller_env()) {
264271
# This function is a modified version of
265272
# https://github.com/r-dbi/RPostgres/blob/master/R/PqResult.R
266273
parse_postprocess <- function(df, bigint) {
267-
268274
df <- col_apply(
269275
df,
270276
function(x) identical(attr(x, "bq_type"), "DATE"),
@@ -337,15 +343,17 @@ set_row_params <- function(nrow, n_max = Inf, start_index = 0L) {
337343
list(n_max = n_max, start_index = start_index)
338344
}
339345

340-
bq_download_plan <- function(n_max,
341-
chunk_size = NULL,
342-
n_chunks = NULL,
343-
start_index = 0) {
346+
bq_download_plan <- function(
347+
n_max,
348+
chunk_size = NULL,
349+
n_chunks = NULL,
350+
start_index = 0
351+
) {
344352
params <- set_chunk_params(n_max, chunk_size, n_chunks)
345353
list(
346-
n_max = n_max,
354+
n_max = n_max,
347355
chunk_size = params$chunk_size,
348-
n_chunks = params$n_chunks,
356+
n_chunks = params$n_chunks,
349357
dat = set_chunk_plan(
350358
n_max,
351359
params$chunk_size,
@@ -373,7 +381,10 @@ set_chunk_plan <- function(n_max, chunk_size, n_chunks, start_index = 0) {
373381
chunk_begin,
374382
chunk_rows,
375383
path = sort(
376-
tempfile(rep_len("bq-download-", length.out = n_chunks), fileext = ".json")
384+
tempfile(
385+
rep_len("bq-download-", length.out = n_chunks),
386+
fileext = ".json"
387+
)
377388
)
378389
)
379390
}
@@ -390,7 +401,10 @@ bq_download_chunk_handle <- function(x, begin = 0L, max_results = 1e4) {
390401
maxResults = format(max_results, scientific = FALSE)
391402
)
392403

393-
url <- paste0(base_url, bq_path(x$project, dataset = x$dataset, table = x$table, data = ""))
404+
url <- paste0(
405+
base_url,
406+
bq_path(x$project, dataset = x$dataset, table = x$table, data = "")
407+
)
394408
url <- httr::modify_url(url, query = prepare_bq_query(query))
395409

396410
if (bq_has_token()) {

R/bq-field.R

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@
3030
#'
3131
#' # as_bq_fields() can also take a data frame
3232
#' as_bq_fields(mtcars)
33-
bq_field <- function(name, type, mode = "NULLABLE", fields = list(), description = NULL) {
33+
bq_field <- function(
34+
name,
35+
type,
36+
mode = "NULLABLE",
37+
fields = list(),
38+
description = NULL
39+
) {
3440
check_string(name)
3541
check_string(type)
3642
check_string(mode)

R/bq-job.R

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,12 @@ bq_job_show_statistics <- function(x) {
7171
#' @export
7272
#' @name api-job
7373
#' @inheritParams rlang::args_error_context
74-
bq_job_wait <- function(x,
75-
quiet = getOption("bigrquery.quiet"),
76-
pause = 0.5,
77-
call = caller_env()) {
74+
bq_job_wait <- function(
75+
x,
76+
quiet = getOption("bigrquery.quiet"),
77+
pause = 0.5,
78+
call = caller_env()
79+
) {
7880
x <- as_bq_job(x)
7981
quiet <- check_quiet(quiet)
8082
check_number_decimal(pause)
@@ -102,15 +104,16 @@ bq_job_wait <- function(x,
102104
}
103105
if (!quiet) cli::cli_progress_done()
104106

105-
106107
errors <- status$errors
107108
if (length(errors) > 0) {
108109
if (length(errors) > 1) {
109110
# First error says to look in errors[]
110111
errors <- errors[-1]
111112
}
112113

113-
bullets <- map_chr(errors, function(x) paste0(x$message, " [", x$reason, "]"))
114+
bullets <- map_chr(errors, function(x) {
115+
paste0(x$message, " [", x$reason, "]")
116+
})
114117
bullets <- set_names(bullets, "x")
115118
cli::cli_abort(c("Job {x} failed", bullets), call = call)
116119
}

0 commit comments

Comments
 (0)