Skip to content
Open
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
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,8 @@ See [#2611](https://github.com/Rdatatable/data.table/issues/2611) for details. T

7. In rare situations a data.table object may lose its internal attribute that holds a self-reference. New helper function `.selfref.ok()` tests just that. It is only intended for technical use cases. See manual for examples.

8. `test()` gains new argument `requires_utf8` to skip tests when UTF-8 support is not available, [#7336](https://github.com/Rdatatable/data.table/issues/7336). Thanks @MichaelChirico for the suggestion and @ben-schwen for the implementation.

## data.table [v1.17.8](https://github.com/Rdatatable/data.table/milestone/41) (6 July 2025)

1. Internal functions used to signal errors are now marked as non-returning, silencing a compiler warning about potentially unchecked allocation failure. Thanks to Prof. Brian D. Ripley for the report and @aitap for the fix, [#7070](https://github.com/Rdatatable/data.table/pull/7070).
Expand Down
18 changes: 17 additions & 1 deletion R/test.data.table.R
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,9 @@ gc_mem = function() {
# nocov end
}

test = function(num,x,y=TRUE,error=NULL,warning=NULL,message=NULL,output=NULL,notOutput=NULL,ignore.warning=NULL,options=NULL,env=NULL) {
utf8_check = function(test_str) identical(test_str, enc2native(test_str))

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) {
if (!is.null(env)) {
old = Sys.getenv(names(env), names=TRUE, unset=NA)
to_unset = !lengths(env)
Expand All @@ -375,6 +377,20 @@ test = function(num,x,y=TRUE,error=NULL,warning=NULL,message=NULL,output=NULL,no
Sys.unsetenv(names(old)[!is_preset])
}, add=TRUE)
}
# Check UTF-8 requirement
if (!isFALSE(requires_utf8)) {
test_str = if (isTRUE(requires_utf8)) "\u00F1\u00FC\u3093" else requires_utf8
if (!utf8_check(test_str)) {
# nocov start
last_utf8_skip = get0("last_utf8_skip", parent.frame(), ifnotfound=0, inherits=TRUE)
if (num - last_utf8_skip >= 1) {
catf("Test %s skipped because required UTF-8 symbols cannot be represented in native encoding.\n", num)
}
assign("last_utf8_skip", num, parent.frame(), inherits=TRUE)
return(invisible(TRUE))
# nocov end
}
}
# Usage:
# i) tests that x equals y when both x and y are supplied, the most common usage
# ii) tests that x is TRUE when y isn't supplied
Expand Down
Loading
Loading