Skip to content

Commit 4f5e30a

Browse files
clean more nesting issues
1 parent f9a9bbd commit 4f5e30a

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

R/io.R

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,34 @@ transform_utf8_one <- function(path, fun, dry) {
3131
identical_content <- identical(file_with_info$text, new)
3232
identical <- identical_content && !file_with_info$missing_EOF_line_break
3333
if (!identical) {
34-
if (dry == "fail") {
35-
rlang::abort(
36-
paste0(
37-
"File `", path, "` would be modified by styler and argument dry",
38-
" is set to 'fail'."
39-
),
40-
class = "dryError"
41-
)
42-
} else if (dry == "on") {
43-
# don't do anything
44-
} else if (dry == "off") {
45-
write_utf8(new, path)
46-
} else {
47-
# not implemented
48-
}
34+
switch(dry,
35+
"fail" = {
36+
rlang::abort(
37+
paste0(
38+
"File `", path, "` would be modified by styler and argument dry",
39+
" is set to 'fail'."
40+
),
41+
class = "dryError"
42+
)
43+
},
44+
"on" = {
45+
# don't do anything
46+
},
47+
"off" = {
48+
write_utf8(new, path)
49+
},
50+
{
51+
# not implemented
52+
}
53+
)
4954
}
5055
!identical
5156
},
5257
error = function(e) {
5358
if (inherits(e, "dryError")) {
5459
rlang::abort(conditionMessage(e))
55-
} else {
56-
warn(paste0("When processing ", path, ": ", conditionMessage(e)))
5760
}
61+
warn(paste0("When processing ", path, ": ", conditionMessage(e)))
5862
NA
5963
}
6064
)

R/utils.R

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,10 @@ calls_sys <- function(sys_call, ...) {
117117
#' option was not set.
118118
#' @keywords internal
119119
option_read <- function(x, default = NULL, error_if_not_found = TRUE) {
120-
if (x %in% names(options()) || !error_if_not_found) {
121-
getOption(x, default)
122-
} else {
120+
if (!(x %in% names(options())) && error_if_not_found) {
123121
rlang::abort(paste("R option", x, "must be set."))
124122
}
123+
getOption(x, default)
125124
}
126125

127126
#' @keywords internal

0 commit comments

Comments
 (0)