Skip to content

Commit 3fdb273

Browse files
committed
Make check_encoding() more relaxed, as in readr
Closes #559
1 parent 405393d commit 3fdb273

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# vroom (development version)
22

3+
* `locale(encoding =)` now warns, instead of errors, when the encoding cannot be found in `iconvlist()` return value. This removes an unnecessary blocker on platforms like Alpine Linux where the output doesn't reflect actual capabilities.
4+
35
* vroom no longer uses `STDVEC_DATAPTR()` and takes the recommended approach for phasing out usage of `DATAPTR()` (#561).
46

57
# vroom 1.6.6

R/locale.R

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,29 @@ check_tz <- function(x) {
130130
stop("Unknown TZ ", x, call. = FALSE)
131131
}
132132
}
133+
134+
# see https://github.com/tidyverse/readr/pull/1537 for why this more relaxed
135+
# than you might expect (and than it used to be)
133136
check_encoding <- function(x) {
134137
stopifnot(is.character(x), length(x) == 1)
135138

136-
if (tolower(x) %in% tolower(iconvlist())) {
139+
# portable encoding names
140+
if (x %in% c("latin1", "UTF-8")) {
137141
return(TRUE)
138142
}
139143

140-
stop("Unknown encoding ", x, call. = FALSE)
144+
# 'iconvlist' could be incomplete (musl) or even unavailable
145+
known <- tryCatch(iconvlist(), error = identity)
146+
if (inherits(known, "error")) {
147+
warning("Could not check `encoding` against `iconvlist()`.", call. = FALSE)
148+
} else if (tolower(x) %in% tolower(known)) {
149+
TRUE
150+
} else {
151+
warning(
152+
"Unknown encoding ",
153+
encodeString(x, quote = '"'),
154+
".",
155+
call. = FALSE
156+
)
157+
}
141158
}

0 commit comments

Comments
 (0)