Skip to content

Commit 9fa042a

Browse files
Merge pull request #866 from lorenzwalthert/remove-deps
- Cut-down on dependencies (#866).
2 parents 4310668 + 73a0413 commit 9fa042a

File tree

13 files changed

+35
-71
lines changed

13 files changed

+35
-71
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ Description: Pretty-prints R code without changing the user's formatting
1616
License: MIT + file LICENSE
1717
URL: https://github.com/r-lib/styler, https://styler.r-lib.org
1818
BugReports: https://github.com/r-lib/styler/issues
19+
Depends:
20+
R (>= 3.4.0)
1921
Imports:
20-
backports (>= 1.1.0),
2122
cli (>= 1.1.0),
2223
glue,
2324
magrittr (>= 2.0.0),
@@ -29,7 +30,6 @@ Imports:
2930
tibble (>= 1.4.2),
3031
tools,
3132
withr (>= 1.0.0),
32-
xfun (>= 0.1)
3333
Suggests:
3434
data.tree (>= 0.1.6),
3535
digest,

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
(also used by {precommit}).
1010
* rename default branch to main (#859).
1111
* Fix argument name `filetype` in Example for `style_dir()` (#855).
12+
* Bump minimal R requirement to 3.4 in line with the [tidyverse](https://www.tidyverse.org/blog/2019/04/r-version-support/), which
13+
allowed to remove the dependency at {backports} and some exception handling.
14+
* Remove dependency on {xfun} (#866).
1215

1316
# styler 1.6.2
1417

R/io.R

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ transform_utf8_one <- function(path, fun, dry) {
4242
} else if (dry == "on") {
4343
# don't do anything
4444
} else if (dry == "off") {
45-
xfun::write_utf8(new, path)
45+
write_utf8(new, path)
4646
} else {
4747
# not implemented
4848
}
@@ -114,3 +114,10 @@ read_utf8_bare <- function(con, warn = TRUE) {
114114
invalid_utf8 <- function(x) {
115115
which(!is.na(x) & is.na(iconv(x, "UTF-8", "UTF-8")))
116116
}
117+
118+
#' Drop-in replacement for `xfun::write_utf8()`
119+
#' @keywords internal
120+
write_utf8 <- function(text, con, ...) {
121+
withr::local_options(encoding = "native.enc")
122+
writeLines(enc2utf8(text), con, ..., useBytes = TRUE)
123+
}

R/parse.R

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ add_id_and_short <- function(pd) {
127127
#' @importFrom magrittr or
128128
#' @keywords internal
129129
ensure_correct_txt <- function(pd, text) {
130-
ensure_valid_pd(pd)
131130
is_problematic_text <- or(
132131
is_insufficiently_parsed_string(pd),
133132
is_insufficiently_parsed_number(pd)
@@ -173,30 +172,6 @@ ensure_correct_txt <- function(pd, text) {
173172
arrange_pos_id()
174173
}
175174

176-
#' Ensure that the parse data is valid
177-
#'
178-
#' Test whether all non-terminals have at least one child and throw an error
179-
#' otherwise. As this is check is rather expensive, it is only
180-
#' carried out for configurations we have good reasons to expect problems.
181-
#' @param pd A parse table.
182-
#' @importFrom rlang abort
183-
#' @keywords internal
184-
ensure_valid_pd <- function(pd) {
185-
if (getRversion() < "3.2") {
186-
non_terminals <- pd %>%
187-
filter(terminal == FALSE)
188-
valid_pd <- non_terminals$id %>%
189-
map_lgl(~ .x %in% pd$parent) %>%
190-
all()
191-
if (!valid_pd) {
192-
abort(paste(
193-
"The parse data is not valid and the problem is most likely related",
194-
"to the parser in base R. Please install R >= 3.2 and try again."
195-
))
196-
}
197-
}
198-
TRUE
199-
}
200175

201176
#' Identify strings that were not fully parsed
202177
#'

R/roxygen-examples-find.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ identify_start_to_stop_of_roxygen_examples_from_text <- function(text) {
2222
}
2323

2424
identify_start_to_stop_of_roxygen_examples <- function(path) {
25-
content <- xfun::read_utf8(path)
25+
content <- read_utf8_bare(path)
2626
identify_start_to_stop_of_roxygen_examples_from_text(content)
2727
}
2828

R/testing.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ transform_and_check <- function(in_item, out_item,
110110
write_tree = NA,
111111
out_tree = "_tree", ...) {
112112
write_tree <- set_arg_write_tree(write_tree)
113-
read_in <- xfun::read_utf8(in_item)
113+
read_in <- read_utf8_bare(in_item)
114114
if (write_tree) {
115115
create_tree(read_in) %>%
116116
write.table(out_tree,

R/transform-files.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ parse_transform_serialize_r <- function(text,
232232
return("")
233233
}
234234
transformers <- transformers_drop(
235-
if (getRversion() < 3.4) text else pd_nested$text[!pd_nested$is_cached],
235+
pd_nested$text[!pd_nested$is_cached],
236236
transformers
237237
)
238238

R/ui-styling.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ prettify_any <- function(transformers,
312312
#' @inheritSection style_pkg Round trip validation
313313
#' @examples
314314
#' file <- tempfile("styler", fileext = ".R")
315-
#' xfun::write_utf8("1++1", file)
315+
#' writeLines("1++1", file)
316316
#'
317317
#' # the following is identical (because of ... and defaults),
318318
#' # but the first is most convenient:
@@ -325,7 +325,7 @@ prettify_any <- function(transformers,
325325
#' # name levels explicitly to not style less invasive levels
326326
#' style_file(file, scope = I(c("tokens", "spaces")), strict = TRUE)
327327
#'
328-
#' xfun::read_utf8(file)
328+
#' readLines(file)
329329
#' unlink(file)
330330
#' @family stylers
331331
#' @export

R/zzz.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
.onLoad <- function(libname, pkgname) {
2-
backports::import(pkgname, "trimws")
32
op <- options()
43
op.styler <- list(
54
styler.addins_style_transformer = "styler::tidyverse_style()",
@@ -37,8 +36,8 @@ ask_to_switch_to_non_default_cache_root <- function(ask = interactive()) {
3736
"options(styler.cache_root = \"styler\")\n\nin your `.Rprofile`. This ",
3837
"message will only be displayed once in a while.\n"
3938
))
39+
options(styler.cache_root = "styler")
4040
}
41-
options(styler.cache_root = "styler")
4241
}
4342

4443
remove_old_cache_files <- function() {

man/ensure_valid_pd.Rd

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)