Skip to content

Commit ec22ce2

Browse files
committed
usethis::use_tidy_style()
1 parent a0fd244 commit ec22ce2

32 files changed

+129
-73
lines changed

R/compat-vctrs.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#' @export
1111
vec_restore.dribble <- function(x, to, ...) {
12-
dribble_maybe_reconstruct(x)
12+
dribble_maybe_reconstruct(x)
1313
}
1414

1515
# ------------------------------------------------------------------------------

R/dribble.R

+6-3
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,12 @@ as_dribble.data.frame <- function(x, ...) validate_dribble(new_dribble(x))
212212

213213
#' @export
214214
as_dribble.list <- function(x, ...) {
215-
if (length(x) == 0) return(dribble())
215+
if (length(x) == 0) {
216+
return(dribble())
217+
}
216218

217219
required_nms <- c("name", "id", "kind")
218-
stopifnot(map_lgl(x, ~all(required_nms %in% names(.x))))
220+
stopifnot(map_lgl(x, ~ all(required_nms %in% names(.x))))
219221

220222
as_dribble(
221223
tibble(
@@ -248,7 +250,8 @@ as_parent <- function(d) {
248250
if (is_folder_shortcut(d)) {
249251
drive_bullets(c(
250252
i = "Parent specified via {.arg {in_var}} is a shortcut; resolving to \\
251-
its target folder"))
253+
its target folder"
254+
))
252255
d <- shortcut_resolve(d)
253256
}
254257
if (!is_parental(d)) {

R/drive_auth.R

+7-5
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ drive_has_token <- function() {
169169
#' drive_oauth_app()
170170
#' drive_api_key()
171171
#' }
172-
#'
173172
#' \dontrun{
174173
#' # bring your own app via JSON downloaded from Google Developers Console
175174
#' drive_auth_configure(
@@ -259,9 +258,12 @@ local_deauth <- function(env = parent.frame()) {
259258
drive_bullets(c("i" = "Restoring previous auth state.")),
260259
envir = env
261260
)
262-
withr::defer({
263-
.auth$set_cred(original_cred)
264-
.auth$set_auth_active(original_auth_active)
265-
}, envir = env)
261+
withr::defer(
262+
{
263+
.auth$set_cred(original_cred)
264+
.auth$set_auth_active(original_auth_active)
265+
},
266+
envir = env
267+
)
266268
drive_deauth()
267269
}

R/drive_browse.R

+3-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ drive_link <- function(file) {
4343
drive_browse <- function(file = .Last.value) {
4444
file <- as_dribble(file)
4545
links <- drive_link(file)
46-
if (!interactive() || no_file(file)) return(invisible(links))
46+
if (!interactive() || no_file(file)) {
47+
return(invisible(links))
48+
}
4749
if (!single_file(file)) {
4850
drive_bullets(c("v" = "Browsing the first file of {nrow(file)}."))
4951
}

R/drive_create.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ drive_create <- function(name,
117117
"Created Drive file:",
118118
bulletize(gargle_map_cli(out)),
119119
"With MIME type:",
120-
bulletize(gargle_map_cli(purrr::pluck(out, 'drive_resource', 1, 'mimeType')))
120+
bulletize(gargle_map_cli(purrr::pluck(out, "drive_resource", 1, "mimeType")))
121121
))
122122
invisible(out)
123123
}

R/drive_find.R

+10-4
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,10 @@
103103
#'
104104
#' # various ways to specify q search clauses
105105
#' # multiple q's
106-
#' drive_find(q = "name contains 'TEST'",
107-
#' q = "modifiedTime > '2020-07-21T12:00:00'")
106+
#' drive_find(
107+
#' q = "name contains 'TEST'",
108+
#' q = "modifiedTime > '2020-07-21T12:00:00'"
109+
#' )
108110
#' # vector q
109111
#' drive_find(q = c("starred = true", "visibility = 'anyoneWithLink'"))
110112
#'
@@ -149,7 +151,9 @@ drive_find <- function(pattern = NULL,
149151
shared_drive <- shared_drive %||% team_drive
150152
}
151153

152-
if (n_max < 1) return(dribble())
154+
if (n_max < 1) {
155+
return(dribble())
156+
}
153157

154158
params <- toCamel(list2(...))
155159
params[["fields"]] <- params[["fields"]] %||% "*"
@@ -239,6 +243,8 @@ handle_shared_drives <- function(shared_drive, corpus) {
239243
)
240244
corpus <- "allDrives"
241245
}
242-
if (is.null(shared_drive) && is.null(corpus)) return()
246+
if (is.null(shared_drive) && is.null(corpus)) {
247+
return()
248+
}
243249
shared_drive_params(shared_drive, corpus)
244250
}

R/drive_get.R

+3-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ drive_get <- function(path = NULL,
123123
verbose = deprecated(),
124124
team_drive = deprecated()) {
125125
warn_for_verbose(verbose)
126-
if (length(path) + length(id) == 0) return(dribble_with_path())
126+
if (length(path) + length(id) == 0) {
127+
return(dribble_with_path())
128+
}
127129
stopifnot(is.null(path) || is.character(path))
128130
stopifnot(is.null(id) || is.character(id))
129131

R/drive_get_path.R

+22-12
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
drive_reveal_path <- function(x, ancestors = c("none", "parents", "all")) {
66
stopifnot(inherits(x, "dribble"))
7-
if (no_file(x)) return(dribble_with_path())
7+
if (no_file(x)) {
8+
return(dribble_with_path())
9+
}
810
ancestors <- ancestors %||% dribble()
911

1012
if (!inherits(ancestors, "dribble")) {
@@ -48,7 +50,9 @@ sort_out_shared_drive_and_corpus <- function(x) {
4850
drive_get_path <- function(path = NULL,
4951
shared_drive = NULL,
5052
corpus = NULL) {
51-
if (length(path) == 0) return(dribble_with_path())
53+
if (length(path) == 0) {
54+
return(dribble_with_path())
55+
}
5256
stopifnot(is_path(path))
5357
path <- rootize_path(path)
5458

@@ -125,7 +129,7 @@ get_immediate_parents <- function(x) {
125129
resolve_paths <- function(d, folders = dribble()) {
126130
probands <- pthize(d)
127131
ancestors <- pthize(folders)
128-
raw_paths <- map(probands, ~pth(list(.x), ancestors))
132+
raw_paths <- map(probands, ~ pth(list(.x), ancestors))
129133
pretty_paths <- map_chr(raw_paths, pathify)
130134
put_column(d, nm = "path", val = pretty_paths, .after = "name")
131135
}
@@ -146,16 +150,19 @@ pthize <- function(d) {
146150

147151
# turns the output of pth() (a list) into a filepath (a string)
148152
pathify <- function(x) {
149-
x <- map_if(x, ~ .x$id == root_id(), ~ {.x$name <- "~"; .x})
153+
x <- map_if(x, ~ .x$id == root_id(), ~ {
154+
.x$name <- "~"
155+
.x
156+
})
150157

151158
last_mime_type <- pluck(last(x), "mime_type")
152159
last_is_folder <- identical(last_mime_type, drive_mime_type("folder"))
153160
last_is_folder_shortcut <-
154161
identical(last_mime_type, drive_mime_type("shortcut")) &&
155-
identical(
156-
pluck(last(x), "shortcut_details", "targetMimeType"),
157-
drive_mime_type("folder")
158-
)
162+
identical(
163+
pluck(last(x), "shortcut_details", "targetMimeType"),
164+
drive_mime_type("folder")
165+
)
159166
if (last_is_folder || last_is_folder_shortcut) {
160167
nm <- pluck(last(x), "name")
161168
purrr::pluck(x, length(x), "name") <- append_slash(nm)
@@ -216,7 +223,9 @@ finalize <- function(dat, candidates) {
216223

217224
report_weird_stuff <- function(x, indicator, problem) {
218225
weird <- vec_slice(x, x[["status"]] == indicator)
219-
if (vec_size(weird) == 0) return()
226+
if (vec_size(weird) == 0) {
227+
return()
228+
}
220229
drive_bullets(c(
221230
"!" = "Problem with {nrow(weird)} path{?s}: {problem}",
222231
# these really should be sub-bullets, but not possible at this time
@@ -231,7 +240,8 @@ finalize <- function(dat, candidates) {
231240
if (n_empty_string > 0) {
232241
drive_bullets(c(
233242
"!" = "Problem with {n_empty_string} path{?s}: \\
234-
path is empty string"))
243+
path is empty string"
244+
))
235245
}
236246

237247
index <- unlist(scratch$m)
@@ -280,7 +290,7 @@ get_by_name <- function(names, shared_drive = NULL, corpus = NULL) {
280290
} else {
281291
found <- drive_find(
282292
q = or(q_clauses),
283-
#fields = prep_fields(fields),
293+
# fields = prep_fields(fields),
284294
shared_drive = shared_drive, corpus = corpus
285295
)
286296
}
@@ -302,7 +312,7 @@ get_last_path_part <- function(path) {
302312
# why? googledrive encourages the user to use a trailing slash to explicitly
303313
# indicate a path that refers to a folder
304314
slash_pos <- gregexpr(pattern = "/.", path)
305-
no_slash <- map_lgl(slash_pos, ~all(.x == -1))
315+
no_slash <- map_lgl(slash_pos, ~ all(.x == -1))
306316
last_slash <- map_int(slash_pos, max)
307317
ifelse(no_slash, path, substr(path, last_slash + 1, nchar(path)))
308318
}

R/drive_id-class.R

+6-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ as_id.data.frame <- function(x, ...) as_id(validate_dribble(new_dribble(x)))
7272

7373
#' @export
7474
as_id.character <- function(x, ...) {
75-
if (length(x) == 0L) return(new_drive_id())
75+
if (length(x) == 0L) {
76+
return(new_drive_id())
77+
}
7678
out <- map_chr(x, get_one_id)
7779
validate_drive_id(new_drive_id(out))
7880
}
@@ -134,7 +136,9 @@ id_regexp <- "(/d/|/folders/|id=)[^/]+"
134136
is_drive_url <- function(x) grepl("^http", x) & grepl(id_regexp, x)
135137

136138
get_one_id <- function(x) {
137-
if (!grepl("^http|/", x)) return(x)
139+
if (!grepl("^http|/", x)) {
140+
return(x)
141+
}
138142

139143
id_loc <- regexpr(id_regexp, x)
140144
if (id_loc == -1) {

R/drive_mkdir.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#' drive_mkdir("name-squatter-mkdir", path = ghi, overwrite = TRUE)
4242
#'
4343
#' # list everything inside 'ghi'
44-
#' drive_ls('ghi')
44+
#' drive_ls("ghi")
4545
#'
4646
#' # Clean up
4747
#' drive_rm(ghi)

R/drive_publish.R

+2-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ drive_change_publish <- function(file,
8181
n <- nrow(file)
8282
drive_bullets(c(
8383
cli::pluralize(
84-
"{cli::qty(n)}File{?s} now {if (publish) '' else 'NOT '}published:"),
84+
"{cli::qty(n)}File{?s} now {if (publish) '' else 'NOT '}published:"
85+
),
8586
bulletize(gargle_map_cli(file))
8687
))
8788
invisible(drive_reveal(file, "published"))

R/drive_reveal.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ drive_reveal_this <- function(file, this) {
167167
out <- promote(file, elem_snake_case)
168168

169169
if (is_dttm && is.character(out[[elem_snake_case]])) {
170-
out[[elem_snake_case]] <-as.POSIXct(
170+
out[[elem_snake_case]] <- as.POSIXct(
171171
out[[elem_snake_case]],
172172
format = "%Y-%m-%dT%H:%M:%OSZ",
173173
tz = "UTC"

R/drive_rm.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ drive_rm <- function(..., verbose = deprecated()) {
4141
}
4242

4343
# explicitly select on var name to exclude 'path', if present
44-
file <- map(dots, ~as_dribble(.x)[c("name", "id", "drive_resource")])
44+
file <- map(dots, ~ as_dribble(.x)[c("name", "id", "drive_resource")])
4545
file <- vec_rbind(!!!file)
4646
# filter to the unique file ids (multiple parents mean drive_get() and
4747
# therefore as_dribble() can return >1 row representing a single file)

R/shared_drive_find.R

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ shared_drive_find <- function(pattern = NULL,
2525
drive_abort("{.arg pattern} must be a character string.")
2626
}
2727
stopifnot(is.numeric(n_max), n_max >= 0, length(n_max) == 1)
28-
if (n_max < 1) return(dribble())
28+
if (n_max < 1) {
29+
return(dribble())
30+
}
2931

3032
## what could possibly come via `...` here? pageSize (or fields)
3133
params <- toCamel(list2(...))

R/shared_drive_get.R

+9-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
#' shared_drive_get(id = "https://drive.google.com/drive/u/0/folders/KCmiHLXUk9PVA-0AJNG")
2828
#' }
2929
shared_drive_get <- function(name = NULL, id = NULL) {
30-
if (length(name) + length(id) == 0) return(dribble())
30+
if (length(name) + length(id) == 0) {
31+
return(dribble())
32+
}
3133

3234
if (!is.null(name) && is_drive_id(name)) {
3335
id <- name
@@ -61,10 +63,14 @@ get_one_shared_drive_id <- function(id) {
6163
}
6264

6365
shared_drive_from_name <- function(name = NULL) {
64-
if (length(name) == 0) return(dribble())
66+
if (length(name) == 0) {
67+
return(dribble())
68+
}
6569

6670
shared_drives <- shared_drive_find()
67-
if (no_file(shared_drives)) return(dribble())
71+
if (no_file(shared_drives)) {
72+
return(dribble())
73+
}
6874

6975
shared_drives <- shared_drives[shared_drives$name %in% name, ]
7076
## TO DO: message if a name matches 0 or multiple shared drives?

R/team_drive.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ team_drive_update <- function(team_drive, ..., verbose = deprecated()) {
6161

6262
#' @export
6363
#' @rdname deprecated-team-drive-functions
64-
as_team_drive <- function(x, ...) {
64+
as_team_drive <- function(x, ...) {
6565
lifecycle::deprecate_warn("2.0.0", "as_team_drive()", "as_shared_drive()")
6666
as_shared_drive(x, ...)
67-
}
67+
}
6868

6969
#' @export
7070
#' @rdname deprecated-team-drive-functions

R/utils-io.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ writeLines <- function(...) {
77
}
88

99
# https://github.com/gaborcsardi/rencfaq#with-base-r
10-
read_utf8 <- function (path) {
10+
read_utf8 <- function(path) {
1111
opts <- options(encoding = "native.enc")
1212
withr::defer(options(opts))
1313
x <- base::readLines(path, encoding = "UTF-8", warn = FALSE)
@@ -44,7 +44,7 @@ nm_fun <- function(context, user_run = TRUE) {
4444
}
4545

4646
nm_user_run <- function() {
47-
if(as.logical(Sys.getenv("GITHUB_ACTIONS", unset = "false"))) {
47+
if (as.logical(Sys.getenv("GITHUB_ACTIONS", unset = "false"))) {
4848
glue("gha-{Sys.getenv('GITHUB_WORKFLOW')}-{Sys.getenv('GITHUB_RUN_ID')}")
4949
} else {
5050
random_id <- strsplit(uuid::UUIDgenerate(TRUE), "-")[[1]][[1]]

R/utils-paths.R

+11-5
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ rationalize_path_name <- function(path = NULL, name = NULL) {
2525

2626
confirm_clear_path <- function(path, name) {
2727
if (is.null(name) &&
28-
!has_slash(path) &&
29-
drive_path_exists(append_slash(path))) {
28+
!has_slash(path) &&
29+
drive_path_exists(append_slash(path))) {
3030
drive_abort(c(
3131
"Unclear if {.arg path} specifies parent folder or full path \\
3232
to the new file, including its name.",
@@ -37,7 +37,9 @@ confirm_clear_path <- function(path, name) {
3737

3838
drive_path_exists <- function(path) {
3939
stopifnot(is_path(path))
40-
if (length(path) == 0) return(logical(0))
40+
if (length(path) == 0) {
41+
return(logical(0))
42+
}
4143
stopifnot(length(path) == 1)
4244
with_drive_quiet(
4345
some_files(drive_get(path = path))
@@ -107,7 +109,9 @@ is_string <- function(x) length(x) == 1L && is_path(x)
107109

108110
# turn '~' into `~/`
109111
rootize_path <- function(path) {
110-
if (length(path) == 0) return(path)
112+
if (length(path) == 0) {
113+
return(path)
114+
}
111115
stopifnot(is.character(path))
112116
leading_slash <- startsWith(path, "/")
113117
if (any(leading_slash)) {
@@ -123,7 +127,9 @@ has_slash <- function(path) {
123127

124128
## "a/b/" and "a/b" both return "a/b/"
125129
append_slash <- function(path) {
126-
if (length(path) < 1) return(path)
130+
if (length(path) < 1) {
131+
return(path)
132+
}
127133
ifelse(has_slash(path) | path == "", path, paste0(path, "/"))
128134
}
129135

0 commit comments

Comments
 (0)