Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions R/data.table.R
Original file line number Diff line number Diff line change
Expand Up @@ -2430,9 +2430,9 @@ setnames = function(x,old,new,skip_absent=FALSE) {
if (length(old) != ncol) stop("Can't assign ",length(old)," names to a ",ncol," column data.table")
if (anyNA(names(x))) {
# if x somehow has some NA names, which() needs help to return them, #2475
w = which((names(x) != old) | (is.na(names(x)) & !is.na(old)))
w = which((names(x) != old) | (Encoding(names(x)) != Encoding(old)) | (is.na(names(x)) & !is.na(old)))
} else {
w = which(names(x) != old)
w = which(names(x) != old | (Encoding(names(x)) != Encoding(old)))
}
if (!length(w)) return(invisible(x)) # no changes
new = old[w]
Expand Down Expand Up @@ -2462,7 +2462,7 @@ setnames = function(x,old,new,skip_absent=FALSE) {
}
}
}
if (any(w <- new==names(x)[i])) {
if (any(w <- new==names(x)[i] & Encoding(new)==Encoding(names(x)[i]))) {
w = which(!w)
new = new[w]
i = i[w]
Expand Down
14 changes: 13 additions & 1 deletion inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -16054,7 +16054,19 @@ test(2110.2, chmatchdup(c(utf8, utf8), latin1), out)
test(2110.3, chmatchdup(c(latin1, latin1), latin1), out)
test(2110.4, chmatchdup(c(utf8, utf8), utf8), out)

# setnames: names with same content but different encoding is considered as non-equal, #3845
utf8 = c("\u00e7ile", "\u00de")
latin1 = iconv(utf8, from = "UTF-8", to = "latin1")
tbl = as.data.table(setNames(list(1, 2), latin1))
test(2111.01, Encoding(names(tbl)), c('latin1', 'latin1'))
setnames(tbl, utf8)
test(2111.02, Encoding(names(tbl)), c('UTF-8', 'UTF-8'))
setnames(tbl, 1:2, latin1)
test(2111.03, Encoding(names(tbl)), c('latin1', 'latin1'))
setnames(tbl, latin1, utf8)
test(2111.04, Encoding(names(tbl)), c('UTF-8', 'UTF-8'))


###################################
# Add new tests above this line #
###################################