Skip to content

Commit

Permalink
use iconv() to make sure that we use UTF-8 for all characters and fac…
Browse files Browse the repository at this point in the history
…tors
  • Loading branch information
ThierryO committed Oct 22, 2019
1 parent 0af7a5e commit 4cc3774
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion R/meta.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ meta <- function(x, ...) {
#' @importFrom assertthat assert_that is.string noNA
meta.character <- function(x, na = "NA", ...) {
assert_that(is.string(na), noNA(na), no_whitespace(na))
x <- iconv(x, to = "UTF-8")
if (na %in% x) {
stop("one of the strings matches the NA string ('", na, "')
Please use a different NA string or consider using a factor.", call. = FALSE)
Expand Down Expand Up @@ -79,6 +80,7 @@ meta.numeric <- function(x, ...) {
#' @importFrom assertthat assert_that is.flag noNA
meta.factor <- function(x, optimize = TRUE, na = "NA", index, ...) {
assert_that(is.flag(optimize), noNA(optimize))
levels(x) <- iconv(levels(x), to = "UTF-8")
if (missing(index) || is.null(index)) {
index <- seq_along(levels(x))
names(index) <- levels(x)
Expand Down Expand Up @@ -109,7 +111,7 @@ Please use a different NA string or use optimize = TRUE", call. = FALSE)
}

m <- list(class = "factor", na_string = na, optimize = optimize,
labels = enc2utf8(names(index)), index = unname(index),
labels = names(index), index = unname(index),
ordered = is.ordered(x))
class(m) <- "meta_detail"
attr(z, "meta") <- m
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test_b_special.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ expect_equal(

expect_equal(
names(suppressWarnings(write_vc(ds, "test_data_hash", root)))[1],
"2d5325687dcd6a2229b5851bca1c84df6b39da62"
"be6352bd3b0d1b3cd81739a5190c24a277ea16d5"
)
expect_silent({
output_test_data_hash <- read_vc("test_data_hash", root)
})
expect_equal(
names(attr(output_test_data_hash, "source")[1]),
"2d5325687dcd6a2229b5851bca1c84df6b39da62"
"be6352bd3b0d1b3cd81739a5190c24a277ea16d5"
)
attr(output_test_data_hash, "source") <- NULL
expect_equal(
Expand Down

0 comments on commit 4cc3774

Please sign in to comment.