From ed8a6e0f2659aac8f309414c94ec4a291cd52ce9 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Tue, 9 Jul 2024 09:20:28 -0700 Subject: [PATCH 1/4] bump to 3.3.0 --- DESCRIPTION | 2 +- NEWS.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 3a988fb0fe..f61a57e9c4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: data.table Version: 1.15.99 Title: Extension of `data.frame` -Depends: R (>= 3.2.0) +Depends: R (>= 3.3.0) Imports: methods Suggests: bit64 (>= 4.0.0), bit (>= 4.0.4), R.utils, xts, zoo (>= 1.8-1), yaml, knitr, markdown Description: Fast aggregation of large data (e.g. 100GB in RAM), fast ordered joins, fast add/modify/delete of columns by group using no copies at all, list columns, friendly and fast character-separated-value read/write. Offers a natural and flexible syntax, for faster development. diff --git a/NEWS.md b/NEWS.md index 4dae71776f..fd3af0926e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -70,7 +70,7 @@ 2. The documentation for the `fill` argument in `rbind()` and `rbindlist()` now notes the expected behaviour for missing `list` columns when `fill=TRUE`, namely to use `NULL` (not `NA`), [#4198](https://github.com/Rdatatable/data.table/pull/4198). Thanks @sritchie73 for the proposal and fix. -3. data.table now depends on R 3.2.0 (2015) instead of 3.1.0 (2014). 1.17.0 will likely move to R 3.3.0 (2016). Recent versions of R have good features that we would gradually like to incorporate, and we see next to no usage of these very old versions of R. +3. data.table now depends on R 3.3.0 (2016) instead of 3.1.0 (2014). Recent versions of R have good features that we would gradually like to incorporate, and we see next to no usage of these very old versions of R. We originally attempted to bump only to R 3.2.0 in this release, but {knitr} requiring 3.3.0 and `R CMD check` lacking an `--ignore-vignettes` option until 3.3.0 essentially forced our hands. 4. Erroneous assignment calls in `[` with a trailing comma (e.g. ``DT[, `:=`(a = 1, b = 2,)]``) get a friendlier error since this situation is common during refactoring and easy to miss visually. Thanks @MichaelChirico for the fix. From d55d5a0106ab3e45a11cfdc78aa325fdb04dcef3 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Tue, 9 Jul 2024 09:35:58 -0700 Subject: [PATCH 2/4] Assume R>=3.3.0 in most places --- .github/workflows/R-CMD-check-occasional.yaml | 4 +- R/fread.R | 3 - R/utils.R | 3 - inst/tests/nafill.Rraw | 10 --- inst/tests/tests.Rraw | 76 +++++++------------ 5 files changed, 29 insertions(+), 67 deletions(-) diff --git a/.github/workflows/R-CMD-check-occasional.yaml b/.github/workflows/R-CMD-check-occasional.yaml index a2f9efdf90..5e32255e5d 100644 --- a/.github/workflows/R-CMD-check-occasional.yaml +++ b/.github/workflows/R-CMD-check-occasional.yaml @@ -15,7 +15,7 @@ jobs: fail-fast: false matrix: os: [macOS-latest, windows-latest, ubuntu-latest] - r: ['devel', 'release', '3.2', '3.3', '3.4', '3.5', '3.6', '4.0', '4.1', '4.2', '4.3'] + r: ['devel', 'release', '3.3', '3.4', '3.5', '3.6', '4.0', '4.1', '4.2', '4.3'] locale: ['en_US.utf8', 'zh_CN.utf8', 'lv_LV.utf8'] # Chinese for translations, Latvian for collate order (#3502) exclude: # only run non-English locale CI on Ubuntu @@ -28,8 +28,6 @@ jobs: - os: windows-latest locale: 'lv_LV.utf8' # macOS/arm64 only available for R>=4.1.0 - - os: macOS-latest - r: '3.2' - os: macOS-latest r: '3.3' - os: macOS-latest diff --git a/R/fread.R b/R/fread.R index 576c84f219..968eaae762 100644 --- a/R/fread.R +++ b/R/fread.R @@ -78,9 +78,6 @@ yaml=FALSE, autostart=NA, tmpdir=tempdir(), tz="UTC") if (w <- startsWithAny(file, c("https://", "ftps://", "http://", "ftp://", "file://"))) { # avoid grepl() for #2531 # nocov start tmpFile = tempfile(fileext = paste0(".",tools::file_ext(file)), tmpdir=tmpdir) # retain .gz extension in temp filename so it knows to be decompressed further below - if (w<=2L && base::getRversion()<"3.2.2") { # https: or ftps: can be read by default by download.file() since 3.2.2 - stopf("URL requires download.file functionalities from R >=3.2.2. You can still manually download the file and fread the downloaded file.") - } method = if (w==5L) "internal" # force 'auto' when file: to ensure we don't use an invalid option (e.g. wget), #1668 else getOption("download.file.method", default="auto") # http: or ftp: # In text mode on Windows-only, R doubles up \r to make \r\r\n line endings. mode="wb" avoids that. See ?connections:"CRLF" diff --git a/R/utils.R b/R/utils.R index 7d4128a1d5..1e0f9d5d65 100644 --- a/R/utils.R +++ b/R/utils.R @@ -21,9 +21,6 @@ nan_is_na = function(x) { stopf("Argument 'nan' must be NA or NaN") } -if (!exists('startsWith', 'package:base', inherits=FALSE)) { # R 3.3.0; Apr 2016 - startsWith = function(x, stub) substr(x, 1L, nchar(stub))==stub -} # endsWith no longer used from #5097 so no need to backport; prevent usage to avoid dev delay until GLCI's R 3.1.0 test endsWith = function(...) stop("Internal error: use endsWithAny instead of base::endsWith", call.=FALSE) diff --git a/inst/tests/nafill.Rraw b/inst/tests/nafill.Rraw index d3d0057ae2..d98e99982f 100644 --- a/inst/tests/nafill.Rraw +++ b/inst/tests/nafill.Rraw @@ -21,16 +21,6 @@ for (s in sugg) { if (!loaded) cat("\n**** Suggested package",s,"is not installed or has dependencies missing. Tests using it will be skipped.\n\n") } -# Ensure an operation uses C-locale sorting (#3502). For test set-ups/comparisons that use base operations, which are -# susceptible to locale-specific sorting issues, but shouldn't be needed for data.table code, which always uses C sorting. -# TODO(R>=3.3.0): use order(method="radix") as a way to avoid needing this helper -with_c_collate = function(expr) { - old = Sys.getlocale("LC_COLLATE") - on.exit(Sys.setlocale("LC_COLLATE", old)) - Sys.setlocale("LC_COLLATE", "C") - expr -} - x = 1:10 x[c(1:2, 5:6, 9:10)] = NA test(1.01, nafill(x, "locf"), INT(NA,NA,3,4,4,4,7,8,8,8)) diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 4d052caa14..ecf2d2a331 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -68,7 +68,6 @@ if (exists("test.data.table", .GlobalEnv, inherits=FALSE)) { shallow = data.table:::shallow # until exported .shallow = data.table:::.shallow split.data.table = data.table:::split.data.table - if (!exists('startsWith', 'package:base', inherits=FALSE)) startsWith = data.table:::startsWith # R 3.3.0 stopf = data.table:::stopf test = data.table:::test uniqlengths = data.table:::uniqlengths @@ -197,21 +196,6 @@ base_messages = list( NULL ) -# Ensure an operation uses C-locale sorting (#3502). For test set-ups/comparisons that use base operations, which are -# susceptible to locale-specific sorting issues, but shouldn't be needed for data.table code, which always uses C sorting. -# TODO(R>=3.3.0): use order(method="radix") as a way to avoid needing this helper -with_c_collate = function(expr) { - old = Sys.getlocale("LC_COLLATE") - on.exit(Sys.setlocale("LC_COLLATE", old)) - Sys.setlocale("LC_COLLATE", "C") - expr -} - -# strrep is used many times in tests, but is from R 3.3.0, so use this equivalent if it is missing. -if (!exists("strrep", "package:base")) { - strrep = function(x, times) mapply(function(x, times) paste(rep(x, times), collapse=""), rep_len(x, length(times)), times, USE.NAMES=FALSE) -} - ########################## .do_not_rm = ls() # objects that exist at this point should not be removed by rm_all(); e.g. test_*, base_messages, Ctest_dt_win_snprintf, prevtest, etc ########################## @@ -1853,10 +1837,10 @@ test(609, chorder(character()), base::order(character())) test(610, chorder(""), base::order("")) # Extra tests of chorder and chgroup x = sample(LETTERS) -test(610.1, chorder(x), with_c_collate(base::order(x))) +test(610.1, chorder(x), base::order(x, method="radix")) test(610.2, chgroup(x), seq_along(x)) x = sample(LETTERS,1000,replace=TRUE) -test(610.3, chorder(x), with_c_collate(base::order(x))) +test(610.3, chorder(x), base::order(x, method="radix")) test(610.4, unique(x[chgroup(x)]), unique(x)) # := by group @@ -4524,7 +4508,8 @@ for (nvars in seq_along(names(DT))) { combn(names(DT), nvars, simplify=FALSE, function(x) { # simplify=FALSE needed for R 3.1.0 for (i in seq_len(nrow(signs))) { test_no <<- test_no + 1L - ll = as.call(c(as.name("order"), + ll = as.call(c( + as.name("order"), lapply(seq_along(x), function(j) { if (signs[i,j] == 1L) as.name(x[j]) @@ -4534,9 +4519,10 @@ for (nvars in seq_along(names(DT))) { else as.call(list(as.name("-"), as.name(x[j]))) } - }) + }), + method = "radix" )) - test(1223.0 + test_no*0.001, forderv(DT, by=x, order=signs[i,]), with_c_collate(with(DT, eval(ll)))) + test(1223.0 + test_no*0.001, forderv(DT, by=x, order=signs[i,]), with(DT, eval(ll))) } integer() }) @@ -4615,25 +4601,21 @@ test(1240.2, ans2, ans1) # Therefore we check against the non-data.table method ('shell') for correctness (otherwise we'd be # checking data.table code against itself) as well as checking data.table's ported code in R; # i.e. a three-way match. -if (base::getRversion() < "3.3.0") { - base_order <- base::order -} else { - base_order <- function(..., na.last=TRUE, method=c("shell","radix")) { - ans1 = base::order(..., na.last=na.last, method="shell") - if (!is.na(na.last) || base::getRversion()>"3.3.3") { - ans2 = base::order(..., na.last=na.last, method="radix") - if (!identical(ans1,ans2)) stop("Base R's order(,method='shell') != order(,method='radix')") - } else { - # Only when na.last=NA in just R 3.3.0-3.3.3 we don't check shell==radix - # because there was a problem in base R's port of data.table code then when : - # 1) 2 or more vectors were passed to base::order(,method="radix") - # AND 2) na.last=NA - # AND 3) there is a subgroup of size exactly 2 - # AND 4) one of those 2 items in the subgroup is NA and the other is not NA - # See tests 1728.3 and 1728.13. - } - ans1 +base_order <- function(..., na.last=TRUE, method=c("shell","radix")) { + ans1 = base::order(..., na.last=na.last, method="shell") + if (!is.na(na.last) || base::getRversion()>"3.3.3") { + ans2 = base::order(..., na.last=na.last, method="radix") + if (!identical(ans1,ans2)) stop("Base R's order(,method='shell') != order(,method='radix')") + } else { + # Only when na.last=NA in just R 3.3.0-3.3.3 we don't check shell==radix + # because there was a problem in base R's port of data.table code then when : + # 1) 2 or more vectors were passed to base::order(,method="radix") + # AND 2) na.last=NA + # AND 3) there is a subgroup of size exactly 2 + # AND 4) one of those 2 items in the subgroup is NA and the other is not NA + # See tests 1728.3 and 1728.13. } + ans1 } # Test for optimisation of 'order' to 'forder'. Copied to benchmarks.Rraw too. @@ -4792,7 +4774,8 @@ for (i in seq_along(names(DT))) { ans[[i]] = combn(names(DT), i, function(x) { tmp = apply(cj, 1, function(y) { test_no <<- test_no + 1L - ll = as.call(c(as.name("base_order"), + ll = as.call(c( + as.name("base_order"), lapply(seq_along(x), function(j) { if (y[j] == 1L) as.name(x[j]) @@ -4802,14 +4785,15 @@ for (i in seq_along(names(DT))) { else as.call(list(as.name("-"), as.name(x[j]))) } - }) + }), + method = "radix" )) ans1 = forderv(DT, by=x, order=y, na.last=TRUE) # adding tests for both nalast=TRUE and nalast=NA - test(1252.0 + test_no*0.001, ans1, with_c_collate(with(DT, eval(ll)))) + test(1252.0 + test_no*0.001, ans1, with(DT, eval(ll))) test_no <<- test_no + 1L ll <- as.call(c(as.list(ll), na.last=NA)) ans1 = forderv(DT, by=x, order=y, na.last=NA) # nalast=NA here. - test(1252.0 + test_no*0.001, ans1[ans1 != 0], with_c_collate(with(DT, eval(ll)))) + test(1252.0 + test_no*0.001, ans1[ans1 != 0], with(DT, eval(ll))) }) dim(tmp)=NULL list(tmp) @@ -8903,11 +8887,7 @@ test(1622.1, ans1, ans2) test(1622.2, ans1, fread(testDir("issue_1573_fill.txt"), fill=TRUE, sep=" ", na.strings="")) # fix for #989 -# error_msg = if (base::getRversion() < "3.4") "can not be a directory name" else "does not exist" -# Until R v3.3, file.info("~") returned TRUE for isdir. This seems to return NA in current devel. However, it -# correctly identifies that "~" is not a file. So leads to another error message. So removing the error message -# so that it errors properly on both versions. This seems fine to me since we just need it to error. Tested. -test(1623, fread("~"), error="") +test(1623, fread("~"), error="File '~' is a directory") # testing print.rownames option, #1097 (part of #1523) options(datatable.print.rownames = FALSE) From f32d199aae237dfa219e5ebec98e941b63269c53 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Wed, 10 Jul 2024 15:38:51 -0700 Subject: [PATCH 3/4] restore with_c_locale() helper&usage --- inst/tests/tests.Rraw | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index ecf2d2a331..d90b293368 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -196,6 +196,16 @@ base_messages = list( NULL ) +# Ensure an operation uses C-locale sorting (#3502). For test set-ups/comparisons that use base operations, which are +# susceptible to locale-specific sorting issues, but shouldn't be needed for data.table code, which always uses C sorting. +# TODO(R>=3.3.0): use order(method="radix") as a way to avoid needing this helper +with_c_collate = function(expr) { + old = Sys.getlocale("LC_COLLATE") + on.exit(Sys.setlocale("LC_COLLATE", old)) + Sys.setlocale("LC_COLLATE", "C") + expr +} + ########################## .do_not_rm = ls() # objects that exist at this point should not be removed by rm_all(); e.g. test_*, base_messages, Ctest_dt_win_snprintf, prevtest, etc ########################## @@ -1837,10 +1847,10 @@ test(609, chorder(character()), base::order(character())) test(610, chorder(""), base::order("")) # Extra tests of chorder and chgroup x = sample(LETTERS) -test(610.1, chorder(x), base::order(x, method="radix")) +test(610.1, chorder(x), with_c_collate(base::order(x))) test(610.2, chgroup(x), seq_along(x)) x = sample(LETTERS,1000,replace=TRUE) -test(610.3, chorder(x), base::order(x, method="radix")) +test(610.3, chorder(x), with_c_collate(base::order(x))) test(610.4, unique(x[chgroup(x)]), unique(x)) # := by group @@ -4774,8 +4784,7 @@ for (i in seq_along(names(DT))) { ans[[i]] = combn(names(DT), i, function(x) { tmp = apply(cj, 1, function(y) { test_no <<- test_no + 1L - ll = as.call(c( - as.name("base_order"), + ll = as.call(c(as.name("base_order"), lapply(seq_along(x), function(j) { if (y[j] == 1L) as.name(x[j]) @@ -4785,15 +4794,14 @@ for (i in seq_along(names(DT))) { else as.call(list(as.name("-"), as.name(x[j]))) } - }), - method = "radix" + }) )) ans1 = forderv(DT, by=x, order=y, na.last=TRUE) # adding tests for both nalast=TRUE and nalast=NA - test(1252.0 + test_no*0.001, ans1, with(DT, eval(ll))) + test(1252.0 + test_no*0.001, ans1, with_c_collate(with(DT, eval(ll)))) test_no <<- test_no + 1L ll <- as.call(c(as.list(ll), na.last=NA)) ans1 = forderv(DT, by=x, order=y, na.last=NA) # nalast=NA here. - test(1252.0 + test_no*0.001, ans1[ans1 != 0], with(DT, eval(ll))) + test(1252.0 + test_no*0.001, ans1[ans1 != 0], with_c_collate(with(DT, eval(ll)))) }) dim(tmp)=NULL list(tmp) From 89e83c720b20cc639c31a02919d8e720467c1822 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Wed, 10 Jul 2024 15:39:40 -0700 Subject: [PATCH 4/4] one more --- inst/tests/tests.Rraw | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index d90b293368..3cc0f3abfc 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -4518,8 +4518,7 @@ for (nvars in seq_along(names(DT))) { combn(names(DT), nvars, simplify=FALSE, function(x) { # simplify=FALSE needed for R 3.1.0 for (i in seq_len(nrow(signs))) { test_no <<- test_no + 1L - ll = as.call(c( - as.name("order"), + ll = as.call(c(as.name("order"), lapply(seq_along(x), function(j) { if (signs[i,j] == 1L) as.name(x[j]) @@ -4529,10 +4528,9 @@ for (nvars in seq_along(names(DT))) { else as.call(list(as.name("-"), as.name(x[j]))) } - }), - method = "radix" + }) )) - test(1223.0 + test_no*0.001, forderv(DT, by=x, order=signs[i,]), with(DT, eval(ll))) + test(1223.0 + test_no*0.001, forderv(DT, by=x, order=signs[i,]), with_c_collate(with(DT, eval(ll)))) } integer() })