Skip to content

Commit

Permalink
Remove helper get_encoding() as it is only used in locale()
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdesmet committed Jul 17, 2024
1 parent 2968efe commit 1f8d002
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 36 deletions.
31 changes: 0 additions & 31 deletions R/get_encoding.R

This file was deleted.

17 changes: 13 additions & 4 deletions R/locale.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
#' @family read functions
#' @noRd
locale <- function(package, resource_name) {
resource <- get_resource(package, resource_name)
schema <- get_schema(package, resource_name)
fields <- schema$fields

# Decimal mark
# Set decimal mark
d_chars <- purrr::map_chr(fields, ~ .x$decimalChar %||% NA_character_)
d_chars <- unique_sorted(d_chars)
if (length(d_chars) == 0 || (length(d_chars) == 1 && d_chars[1] == ".")) {
Expand All @@ -25,7 +26,7 @@ locale <- function(package, resource_name) {
)
}

# Grouping mark
# Set grouping mark
g_chars <- purrr::map_chr(fields, ~ .x$groupChar %||% NA_character_)
g_chars <- unique_sorted(g_chars)
if (length(g_chars) == 0 || (length(g_chars) == 1 && g_chars[1] == "")) {
Expand All @@ -39,8 +40,16 @@ locale <- function(package, resource_name) {
)
}

# Encoding
encoding <- get_encoding(package, resource_name)
# Set encoding
encoding <- resource$encoding %||% "UTF-8" # Set default to UTF-8
if (!tolower(encoding) %in% tolower(iconvlist())) {
cli::cli_warn(
"Unknown encoding {.field {encoding}}. Reading file(s) with UTF-8
encoding.",
class = "frictionless_warning_resource_encoding_unknown"
)
encoding <- "UTF-8"
}

readr::locale(
decimal_mark = decimal_mark,
Expand Down
2 changes: 1 addition & 1 deletion R/read_resource.R
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ read_resource <- function(package, resource_name, col_select = NULL) {
)
}

# Create locale with encoding, decimal_mark and grouping_mark
# Create locale with decimal_mark, grouping_mark and encoding
locale <- locale(package, resource_name)

# Create col_types: list(<collector_character>, <collector_logical>, ...)
Expand Down

0 comments on commit 1f8d002

Please sign in to comment.