Skip to content

Commit e9ecf69

Browse files
committed
fix warnings of sys.source
1 parent 45dc9e7 commit e9ecf69

File tree

2 files changed

+93
-81
lines changed

2 files changed

+93
-81
lines changed

R/test.data.table.R

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,8 @@ gc_mem = function() {
361361
# nocov end
362362
}
363363

364+
utf8_check = function(test_str) identical(test_str, enc2native(test_str))
365+
364366
test = function(num,x,y=TRUE,error=NULL,warning=NULL,message=NULL,output=NULL,notOutput=NULL,ignore.warning=NULL,options=NULL,env=NULL,requires_utf8=FALSE) {
365367
if (!is.null(env)) {
366368
old = Sys.getenv(names(env), names=TRUE, unset=NA)
@@ -376,23 +378,18 @@ test = function(num,x,y=TRUE,error=NULL,warning=NULL,message=NULL,output=NULL,no
376378
}, add=TRUE)
377379
}
378380
# Check UTF-8 requirement
379-
if (requires_utf8) {
380-
utf8_available = l10n_info()$`UTF-8` || {
381-
lc_ctype = Sys.getlocale('LC_CTYPE')
382-
lc_wantctype = 'en_US.UTF-8'
383-
# Japanese multibyte characters require utf8. As of 2025, we're likely to be already running in a UTF-8 locale, but if not, try this setlocale() call as a last chance.
384-
# Unfortunately, there is no guaranteed, portable way of switching to UTF-8 US English.
385-
# Avoid the warning upon possible failure, #7210.
386-
lc_newctype = suppressWarnings(Sys.setlocale('LC_CTYPE', lc_wantctype))
387-
if (identical(lc_newctype, lc_wantctype)) {
388-
on.exit(Sys.setlocale('LC_CTYPE', lc_ctype), add=TRUE)
389-
TRUE
390-
} else FALSE
381+
if (!isFALSE(requires_utf8)) {
382+
# Test string with common UTF-8 symbols that appear in tests: ñ (test 2266), ü (test 1229.3), ん (Japanese)
383+
# If requires_utf8 is TRUE, use the default test string; if it's a string, use that string
384+
if (isTRUE(requires_utf8)) {
385+
test_str = "a\u00F1o \u00FCber \u3093"
386+
} else {
387+
test_str = requires_utf8
391388
}
392-
if (!utf8_available) {
389+
if (!utf8_check(test_str)) {
393390
last_utf8_skip = get0("last_utf8_skip", parent.frame(), ifnotfound=0, inherits=TRUE)
394391
if (num - last_utf8_skip >= 1) {
395-
catf("Test %s skipped because it needs a UTF-8 locale.\n", num)
392+
catf("Test %s skipped because required UTF-8 symbols cannot be represented in native encoding.\n", num)
396393
}
397394
assign("last_utf8_skip", num, parent.frame(), inherits=TRUE)
398395
return(invisible(TRUE))

inst/tests/tests.Rraw

Lines changed: 82 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -3569,27 +3569,30 @@ test(1086, class(DT$last.x), c("POSIXct", "POSIXt"))
35693569
test(1087, class(DT$last.x1), "ITime")
35703570

35713571
# chmatch on 'unknown' encoding (e.g. as.character(as.symbol("\u00E4")) )falling back to match, #2538 and #4818
3572-
x1 <- c("al\u00E4", "ala", "\u00E4allc", "coep")
3573-
x2 <- c("ala", "al\u00E4")
3574-
test(1088.1, requires_utf8=TRUE, chmatch(x1, x2), match(x1, x2)) # should not fallback to "match"
3575-
test(1088.2, requires_utf8=TRUE, x1 %chin% x2, x1 %in% x2)
3572+
x1 = c("al\u00E4", "ala", "\u00E4allc", "coep")
3573+
x2 = c("ala", "al\u00E4")
3574+
tstc = function(y) unlist(lapply(y, function(x) as.character(as.name(x))), use.names=FALSE)
3575+
test(1088.1, requires_utf8="\u00E4", chmatch(x1, x2), match(x1, x2)) # should not fallback to "match"
3576+
test(1088.2, requires_utf8="\u00E4", x1 %chin% x2, x1 %in% x2)
35763577
# change x1 to symbol to character
3577-
x3 <- unlist(lapply(x1, function(x) as.character(as.name(x))), use.names=FALSE)
3578-
test(1089.1, requires_utf8=TRUE, chmatch(x3, x2), match(x3, x2)) # should fallback to match in "x"
3579-
test(1089.2, requires_utf8=TRUE, x3 %chin% x2, x3 %in% x2) # should fallback to match in "x"
3578+
test(1089.1, requires_utf8="\u00E4", chmatch(tstc(x1), x2), match(tstc(x1), x2)) # should fallback to match in "x"
3579+
test(1089.2, requires_utf8="\u00E4", tstc(x1) %chin% x2, tstc(x1) %in% x2) # should fallback to match in "x"
35803580
# change x2 to symbol to character
3581-
x4 <- unlist(lapply(x2, function(x) as.character(as.name(x))), use.names=FALSE)
3582-
test(1090.1, requires_utf8=TRUE, chmatch(x1,x4), match(x1, x4)) # should fallback to match in "table"
3583-
test(1090.2, requires_utf8=TRUE, x1 %chin% x4, x1 %in% x4)
3581+
test(1090.1, requires_utf8="\u00E4", chmatch(x1,tstc(x2)), match(x1, tstc(x2))) # should fallback to match in "table"
3582+
test(1090.2, requires_utf8="\u00E4", x1 %chin% tstc(x2), x1 %in% tstc(x2))
35843583
# both are symbols to characters
3585-
test(1091.1, requires_utf8=TRUE, chmatch(x3, x4), match(x3, x4)) # should fallback to "match" in "x" as well.
3586-
test(1091.2, requires_utf8=TRUE, x3 %chin% x4, x3 %in% x4)
3584+
test(1091.1, requires_utf8="\u00E4", chmatch(tstc(x1), tstc(x2)), match(tstc(x1), tstc(x2))) # should fallback to "match" in "x" as well.
3585+
test(1091.2, requires_utf8="\u00E4", tstc(x1) %chin% tstc(x2), tstc(x1) %in% tstc(x2))
35873586
# for completness, include test from #2528 of non ascii LHS of := (it could feasibly fail in future due to something other than chmatch)
35883587

3589-
DT = data.table(pas = c(1:5, NA, 6:10), good = c(1:10, NA))
3590-
setnames(DT, "pas", "p\u00E4s")
3591-
test(1092, requires_utf8=TRUE, eval(parse(text="DT[is.na(p\u00E4s), p\u00E4s := 99L]")), data.table("p\u00E4s" = c(1:5, 99L, 6:10), good = c(1:10,NA)))
3592-
test(1093, requires_utf8=TRUE, eval(parse(text="DT[, p\u00E4s := 34L]")), data.table("p\u00E4s" = 34L, good=c(1:10,NA)))
3588+
local(if (utf8_check("\u00E4")) {
3589+
eval(parse(text='
3590+
DT = data.table(pas = c(1:5, NA, 6:10), good = c(1:10, NA))
3591+
setnames(DT, "pas", "p\u00E4s")
3592+
test(1092, requires_utf8="\u00E4", eval(parse(text="DT[is.na(p\u00E4s), p\u00E4s := 99L]")), data.table("p\u00E4s" = c(1:5, 99L, 6:10), good = c(1:10,NA)))
3593+
test(1093, requires_utf8="\u00E4", eval(parse(text="DT[, p\u00E4s := 34L]")), data.table("p\u00E4s" = 34L, good=c(1:10,NA)))
3594+
'))
3595+
} else cat("Tests 1092+1093 skipped because required UTF-8 symbols cannot be represented in native encoding.\n"))
35933596

35943597
# print of unnamed DT with >20 <= 100 rows, #97 (RF#4934)
35953598
DT <- data.table(x=1:25, y=letters[1:25])
@@ -4343,8 +4346,8 @@ test(1163, last(x), character(0))
43434346

43444347
# Bug fix for #5159 - chmatch and character encoding (for some reason this seems to pass the test on a mac as well)
43454348
a<-c("a","\u00E4","\u00DF","z")
4346-
au<-iconv(a,"UTF8","latin1")
4347-
test(1164.1, requires_utf8=TRUE, chmatch(a, au), match(a, au))
4349+
au<-iconv(a,"UTF8","latin1")
4350+
test(1164.1, requires_utf8=c("\u00E4", "\u00DF"), chmatch(a, au), match(a, au))
43484351

43494352
# Bug fix for #73 - segfault when rbindlist on empty data.tables
43504353
x <- as.data.table(BOD)
@@ -4634,18 +4637,24 @@ test(1228.6, class(DT), class(DT[a>1, c:=sum(b), by=a]))
46344637
DT <- data.table(x=1:5, y=10:6)
46354638
test(1229.1, DT[forderv(DT, -1)], error="non-existing column")
46364639
test(1229.2, setkey(DT), data.table(x=1:5, y=10:6, key="x,y"))
4637-
# umlaut in column names (red herring I think, but testing anyway)
4638-
sentEx = data.table(abend = c(1, 1, 0, 0, 2),
4639-
aber = c(0, 1, 0, 0, 0),
4640-
"\u00FCber" = c(1, 0, 0, 0, 0),
4641-
"\u00FCberall" = c(0, 0, 0, 0, 0),
4642-
"\u00FCberlegt" = c(0, 0, 0, 0, 0),
4643-
ID = structure(c(1L, 1L, 2L, 2L, 2L), .Label = c("0019", "0021"), class = "factor"),
4644-
abgeandert = c(1, 1, 1, 0, 0),
4645-
abgebildet = c(0, 0, 1, 1, 0),
4646-
abgelegt = c(0, 0, 0, 0, 3))
4647-
test(1229.3, requires_utf8=TRUE, sentEx[, lapply(.SD, sum), by=ID], data.table(ID=factor(c("0019","0021")), abend=c(2,2), aber=c(1,0), "\u00FCber"=c(1,0),
4648-
"\u00FCberall"=c(0,0), "\u00FCberlegt" = c(0,0), abgeandert=c(2,1), abgebildet = c(0,2), abgelegt=c(0,3)))
4640+
# umlaut in column names (red herring I think, but testing anyway
4641+
local(if (utf8_check("\u00e4\u00f6\u00fc")) {
4642+
eval(parse(text = '
4643+
sentEx = data.table(abend = c(1, 1, 0, 0, 2),
4644+
aber = c(0, 1, 0, 0, 0),
4645+
"\u00FCber" = c(1, 0, 0, 0, 0),
4646+
"\u00FCberall" = c(0, 0, 0, 0, 0),
4647+
"\u00FCberlegt" = c(0, 0, 0, 0, 0),
4648+
ID = structure(c(1L, 1L, 2L, 2L, 2L), .Label = c("0019", "0021"), class = "factor"),
4649+
abgeandert = c(1, 1, 1, 0, 0),
4650+
abgebildet = c(0, 0, 1, 1, 0),
4651+
abgelegt = c(0, 0, 0, 0, 3))
4652+
test(1229.3, sentEx[, lapply(.SD, sum), by=ID], data.table(ID=factor(c("0019","0021")), abend=c(2,2), aber=c(1,0), "\u00FCber"=c(1,0),
4653+
"\u00FCberall"=c(0,0), "\u00FCberlegt" = c(0,0), abgeandert=c(2,1), abgebildet = c(0,2), abgelegt=c(0,3)))
4654+
'))
4655+
} else {
4656+
cat("Tests 1229.3 skipped because required UTF-8 symbols cannot be represented in native encoding.\n")
4657+
})
46494658

46504659
# Test that ad hoc by detects if ordered and dogroups switches to memcpy if contiguous, #1050
46514660
DT = data.table(a=1:3,b=1:6,key="a")
@@ -7938,10 +7947,8 @@ test(1547, foo(1L, 5L, a=2L, "c"), c("2", "c"))
79387947

79397948
# Fix for encoding issues in windows, #563
79407949
f = testDir("issue_563_fread.txt")
7941-
ans1 <- fread(f, sep=",", header=TRUE)
7942-
ans2 <- fread(f, sep=",", header=TRUE, encoding="UTF-8")
7943-
test(1548.1, unique(unlist(lapply(ans1, Encoding))), "unknown")
7944-
test(1548.2, unique(unlist(lapply(ans2, Encoding))), "UTF-8")
7950+
test(1548.1, requires_utf8=TRUE, unique(unlist(lapply(fread(f, sep=",", header=TRUE), Encoding))), "unknown")
7951+
test(1548.2, requires_utf8=TRUE, unique(unlist(lapply(fread(f, sep=",", header=TRUE, encoding="UTF-8"), Encoding))), "UTF-8")
79457952

79467953
# 1549 moved to benchmark.Rraw, #5517
79477954

@@ -17693,8 +17700,9 @@ test(2194.4, endsWithAny(letters, 'e'), error="Internal error.*types or lengths
1769317700
test(2194.5, endsWithAny(NA_character_, 'a'), FALSE)
1769417701
test(2194.6, endsWithAny(character(), 'a'), error="Internal error.*types or lengths incorrect")
1769517702
# file used in encoding tests
17696-
txt = readLines(testDir("issue_563_fread.txt"))
17697-
test(2194.7, requires_utf8=TRUE, endsWithAny(txt, 'B'), error="Internal error.*types or lengths incorrect") # txt is length 5
17703+
needed_chars = "\u0105\u017E\u016B\u012F\u0173\u0117\u0161\u0119"
17704+
txt = parse(text='readLines(testDir("issue_563_fread.txt"))')
17705+
test(2194.7, requires_utf8=needed_chars, endsWithAny(eval(txt), 'B'), error="Internal error.*types or lengths incorrect") # txt is length 5
1769817706
test(2194.8, endsWith('abcd', 'd'), error="Internal error.*use endsWithAny")
1769917707

1770017708
# uniqueN(x, by=character()) was internal error, #4594
@@ -18681,50 +18689,51 @@ ja_ichi = "\u4E00"
1868118689
ja_ni = "\u4E8C"
1868218690
ja_ko = "\u3053"
1868318691
ja_n = "\u3093"
18692+
nc = paste0(accented_a, ja_ichi, ja_ni, ja_ko, ja_n)
1868418693
dots = "..."
1868518694
clean_regex = "^\\d+:\\s+" # removes row numbering from beginning of output
1868618695
# Tests for combining character latin a and acute accent, single row
1868718696
DT = data.table(strrep(accented_a, 4L))
18688-
test(2253.01, requires_utf8=TRUE, options=list(datatable.prettyprint.char = 4L), DT, output=strrep(accented_a, 4L))
18689-
test(2253.02, requires_utf8=TRUE, options=list(datatable.prettyprint.char = 3L), DT, output=paste0(strrep(accented_a, 3L), dots))
18690-
test(2253.03, requires_utf8=TRUE, options=list(datatable.prettyprint.char = 1L), DT, output=paste0(strrep(accented_a, 1L), dots))
18697+
test(2253.01, requires_utf8=nc, options=list(datatable.prettyprint.char = 4L), DT, output=strrep(accented_a, 4L))
18698+
test(2253.02, requires_utf8=nc, options=list(datatable.prettyprint.char = 3L), DT, output=paste0(strrep(accented_a, 3L), dots))
18699+
test(2253.03, requires_utf8=nc, options=list(datatable.prettyprint.char = 1L), DT, output=paste0(strrep(accented_a, 1L), dots))
1869118700
# Tests for full-width japanese character ichi, single row
1869218701
DT = data.table(strrep(ja_ichi, 4L))
18693-
test(2253.04, requires_utf8=TRUE, options=list(datatable.prettyprint.char = 4L), DT, output=strrep(ja_ichi, 4L))
18694-
test(2253.05, requires_utf8=TRUE, options=list(datatable.prettyprint.char = 3L), DT, output=paste0(strrep(ja_ichi, 3L), dots))
18695-
test(2253.06, requires_utf8=TRUE, options=list(datatable.prettyprint.char = 1L), DT, output=paste0(strrep(ja_ichi, 1L), dots))
18702+
test(2253.04, requires_utf8=nc, options=list(datatable.prettyprint.char = 4L), DT, output=strrep(ja_ichi, 4L))
18703+
test(2253.05, requires_utf8=nc, options=list(datatable.prettyprint.char = 3L), DT, output=paste0(strrep(ja_ichi, 3L), dots))
18704+
test(2253.06, requires_utf8=nc, options=list(datatable.prettyprint.char = 1L), DT, output=paste0(strrep(ja_ichi, 1L), dots))
1869618705
# Tests for multiple, different length combining character rows
1869718706
DT = data.table(strrep(accented_a, 1L:4L))
18698-
test(2253.07, requires_utf8=TRUE, options=list(datatable.prettyprint.char = 4L), gsub(clean_regex, "", capture.output(print(DT))[-1L]), strrep(accented_a, 1:4L))
18699-
test(2253.08, requires_utf8=TRUE, options=list(datatable.prettyprint.char = 3L), gsub(clean_regex, "", capture.output(print(DT))[-1L]), c(strrep(accented_a, 1:3), paste0(strrep(accented_a, 3L), dots)))
18700-
test(2253.09, requires_utf8=TRUE, options=list(datatable.prettyprint.char = 1L), gsub(clean_regex, "", capture.output(print(DT))[-1L]), c(accented_a, rep(paste0(accented_a, dots), 3L)))
18707+
test(2253.07, requires_utf8=nc, options=list(datatable.prettyprint.char = 4L), gsub(clean_regex, "", capture.output(print(DT))[-1L]), strrep(accented_a, 1:4L))
18708+
test(2253.08, requires_utf8=nc, options=list(datatable.prettyprint.char = 3L), gsub(clean_regex, "", capture.output(print(DT))[-1L]), c(strrep(accented_a, 1:3), paste0(strrep(accented_a, 3L), dots)))
18709+
test(2253.09, requires_utf8=nc, options=list(datatable.prettyprint.char = 1L), gsub(clean_regex, "", capture.output(print(DT))[-1L]), c(accented_a, rep(paste0(accented_a, dots), 3L)))
1870118710
# Tests for multiple, different length full-width characters
1870218711
DT = data.table(strrep(ja_ichi, 1L:4L))
18703-
test(2253.10, requires_utf8=TRUE, options=list(datatable.prettyprint.char = 4L), gsub(clean_regex, "", capture.output(print(DT))[-1L]), strrep(ja_ichi, 1:4L))
18704-
test(2253.11, requires_utf8=TRUE, options=list(datatable.prettyprint.char = 3L), gsub(clean_regex, "", capture.output(print(DT))[-1L]), c(strrep(ja_ichi, 1:3), paste0(strrep(ja_ichi, 3L), dots)))
18705-
test(2253.12, requires_utf8=TRUE, options=list(datatable.prettyprint.char = 1L), gsub(clean_regex, "", capture.output(print(DT))[-1L]), c(ja_ichi, rep(paste0(ja_ichi, dots), 3L)))
18712+
test(2253.10, requires_utf8=nc, options=list(datatable.prettyprint.char = 4L), gsub(clean_regex, "", capture.output(print(DT))[-1L]), strrep(ja_ichi, 1:4L))
18713+
test(2253.11, requires_utf8=nc, options=list(datatable.prettyprint.char = 3L), gsub(clean_regex, "", capture.output(print(DT))[-1L]), c(strrep(ja_ichi, 1:3), paste0(strrep(ja_ichi, 3L), dots)))
18714+
test(2253.12, requires_utf8=nc, options=list(datatable.prettyprint.char = 1L), gsub(clean_regex, "", capture.output(print(DT))[-1L]), c(ja_ichi, rep(paste0(ja_ichi, dots), 3L)))
1870618715
# Tests for combined characters, multiple columns
1870718716
DT = data.table(paste0(ja_ichi), strrep(ja_ni, 2L), strrep(ja_ko, 3L), strrep(accented_a, 2L), "aaa")
18708-
test(2253.13, requires_utf8=TRUE, options=list(datatable.prettyprint.char = 4L), capture.output(print(DT))[-1L], paste("1:", ja_ichi, strrep(ja_ni, 2L), strrep(ja_ko, 3L), strrep(accented_a, 2L), "aaa"))
18709-
test(2253.14, requires_utf8=TRUE, options=list(datatable.prettyprint.char = 3L), capture.output(print(DT))[-1L], paste("1:", ja_ichi, strrep(ja_ni, 2L), strrep(ja_ko, 3L), strrep(accented_a, 2L), "aaa"))
18710-
test(2253.15, requires_utf8=TRUE, options=list(datatable.prettyprint.char = 2L), capture.output(print(DT))[-1L], paste("1:", ja_ichi, strrep(ja_ni, 2), paste0(strrep(ja_ko, 2), dots) , strrep(accented_a, 2), "aa..."))
18711-
test(2253.16, requires_utf8=TRUE, options=list(datatable.prettyprint.char = 1L), capture.output(print(DT))[-1L], paste("1:", ja_ichi, paste0(ja_ni, dots), paste0(ja_ko, dots), paste0(accented_a, dots), "a..."))
18717+
test(2253.13, requires_utf8=nc, options=list(datatable.prettyprint.char = 4L), capture.output(print(DT))[-1L], paste("1:", ja_ichi, strrep(ja_ni, 2L), strrep(ja_ko, 3L), strrep(accented_a, 2L), "aaa"))
18718+
test(2253.14, requires_utf8=nc, options=list(datatable.prettyprint.char = 3L), capture.output(print(DT))[-1L], paste("1:", ja_ichi, strrep(ja_ni, 2L), strrep(ja_ko, 3L), strrep(accented_a, 2L), "aaa"))
18719+
test(2253.15, requires_utf8=nc, options=list(datatable.prettyprint.char = 2L), capture.output(print(DT))[-1L], paste("1:", ja_ichi, strrep(ja_ni, 2), paste0(strrep(ja_ko, 2), dots) , strrep(accented_a, 2), "aa..."))
18720+
test(2253.16, requires_utf8=nc, options=list(datatable.prettyprint.char = 1L), capture.output(print(DT))[-1L], paste("1:", ja_ichi, paste0(ja_ni, dots), paste0(ja_ko, dots), paste0(accented_a, dots), "a..."))
1871218721
# Tests for multiple columns, multiple rows
1871318722
DT = data.table(strrep(ja_ko, 1:3L), strrep(ja_n, 2:4L), strrep(accented_a, 3))
18714-
test(2253.17, requires_utf8=TRUE, options=list(datatable.prettyprint.char = 4L), gsub(clean_regex, "", capture.output(print(DT))[-1L]),
18723+
test(2253.17, requires_utf8=nc, options=list(datatable.prettyprint.char = 4L), gsub(clean_regex, "", capture.output(print(DT))[-1L]),
1871518724
c(paste0(ja_ko, " ", strrep(ja_n, 2L), " ", strrep(accented_a, 3L)),
1871618725
paste0(strrep(ja_ko, 2L), " ", strrep(ja_n, 3L), " ", strrep(accented_a, 3L)),
1871718726
paste(strrep(ja_ko, 3L), strrep(ja_n, 4L), strrep(accented_a, 3L))))
18718-
test(2253.18, requires_utf8=TRUE, options=list(datatable.prettyprint.char = 3L), gsub(clean_regex, "", capture.output(print(DT))[-1L]),
18727+
test(2253.18, requires_utf8=nc, options=list(datatable.prettyprint.char = 3L), gsub(clean_regex, "", capture.output(print(DT))[-1L]),
1871918728
c(paste0(ja_ko, " ", strrep(ja_n, 2L), " ", strrep(accented_a, 3L)),
1872018729
paste0(strrep(ja_ko, 2L), " ", strrep(ja_n, 3L), " ", strrep(accented_a, 3L)),
1872118730
paste(strrep(ja_ko, 3L), paste0(strrep(ja_n, 3L), dots), strrep(accented_a, 3L))))
18722-
test(2253.19, requires_utf8=TRUE, options=list(datatable.prettyprint.char = 1L), gsub(clean_regex, "", capture.output(print(DT))[-1L]),
18731+
test(2253.19, requires_utf8=nc, options=list(datatable.prettyprint.char = 1L), gsub(clean_regex, "", capture.output(print(DT))[-1L]),
1872318732
c(paste0(ja_ko, " ", paste0(ja_n, dots), " ", paste0(accented_a, dots)),
1872418733
paste0(c(ja_ko, ja_n, accented_a), dots, collapse=" "),
1872518734
paste0(c(ja_ko, ja_n, accented_a), dots, collapse=" ")))
1872618735
# test for data.table with NA, #6441
18727-
test(2253.20, requires_utf8=TRUE, options=list(datatable.prettyprint.char = 1L), data.table(a = c("abc", NA)), output=" a\n1: a...\n2: <NA>")
18736+
test(2253.20, requires_utf8=nc, options=list(datatable.prettyprint.char = 1L), data.table(a = c("abc", NA)), output=" a\n1: a...\n2: <NA>")
1872818737

1872918738
# allow 1-D matrix in j for consistency, #783
1873018739
DT=data.table(a = rep(1:2, 3), b = 1:6)
@@ -20861,17 +20870,23 @@ x = data.table(a=1, b=2L)
2086120870
y = data.table(c=1.5, d=1L)
2086220871
test(2297.31, y[x, on=.(c == a, d == a), nomatch=NULL], output="Empty data.table (0 rows and 3 cols): c,d,b")
2086320872

20864-
# rbindlist(l, use.names=TRUE) should handle different colnames encodings #5452
20865-
x = data.table(a = 1, b = 2, c = 3)
20866-
y = data.table(x = 4, y = 5, z = 6)
20867-
# a-umlaut, o-umlaut, u-umlaut
20868-
setnames(x , c("\u00e4", "\u00f6", "\u00fc"))
20869-
setnames(y , iconv(c("\u00f6", "\u00fc", "\u00e4"), from = "UTF-8", to = "latin1"))
20870-
test(2298.1, requires_utf8=TRUE, rbindlist(list(x,y), use.names=TRUE), data.table("\u00e4"=c(1,6), "\u00f6"=c(2,4), "\u00fc"=c(3,5)))
20871-
test(2298.2, requires_utf8=TRUE, rbindlist(list(y,x), use.names=TRUE), data.table("\u00f6"=c(4,2), "\u00fc"=c(5,3), "\u00e4"=c(6,1)))
20872-
set(y, j="\u00e4", value=NULL)
20873-
test(2298.3, requires_utf8=TRUE, rbindlist(list(x,y), use.names=TRUE, fill=TRUE), data.table("\u00e4"=c(1,NA), "\u00f6"=c(2,4), "\u00fc"=c(3,5)))
20874-
test(2298.4, requires_utf8=TRUE, rbindlist(list(y,x), use.names=TRUE, fill=TRUE), data.table("\u00f6"=c(4,2), "\u00fc"=c(5,3), "\u00e4"=c(NA,1)))
20873+
local(if (utf8_check("\u00e4\u00f6\u00fc")) {
20874+
# rbindlist(l, use.names=TRUE) should handle different colnames encodings #5452
20875+
x = data.table(a = 1, b = 2, c = 3)
20876+
y = data.table(x = 4, y = 5, z = 6)
20877+
# a-umlaut, o-umlaut, u-umlaut
20878+
eval(parse(text = '
20879+
setnames(x , c("\u00e4", "\u00f6", "\u00fc"))
20880+
setnames(y , iconv(c("\u00f6", "\u00fc", "\u00e4"), from = "UTF-8", to = "latin1"))
20881+
test(2298.1, rbindlist(list(x,y), use.names=TRUE), data.table("\u00e4"=c(1,6), "\u00f6"=c(2,4), "\u00fc"=c(3,5)))
20882+
test(2298.2, rbindlist(list(y,x), use.names=TRUE), data.table("\u00f6"=c(4,2), "\u00fc"=c(5,3), "\u00e4"=c(6,1)))
20883+
set(y, j="\u00e4", value=NULL)
20884+
test(2298.3, rbindlist(list(x,y), use.names=TRUE, fill=TRUE), data.table("\u00e4"=c(1,NA), "\u00f6"=c(2,4), "\u00fc"=c(3,5)))
20885+
test(2298.4, rbindlist(list(y,x), use.names=TRUE, fill=TRUE), data.table("\u00f6"=c(4,2), "\u00fc"=c(5,3), "\u00e4"=c(NA,1)))
20886+
'))
20887+
} else {
20888+
cat("Tests 2298.* skipped because they need a UTF-8 locale.\n")
20889+
})
2087520890

2087620891
# #6592: printing nested single-column frames
2087720892
test(2299.01, format_list_item(data.frame(a=1)), output="<data.frame[1x1]>")

0 commit comments

Comments
 (0)