From b50bce8f106b6585773bbf1326609b83f7e77586 Mon Sep 17 00:00:00 2001 From: jangorecki Date: Fri, 24 Nov 2023 17:56:12 +0100 Subject: [PATCH] zlib optional also for tests --- DESCRIPTION | 1 - R/fwrite.R | 2 ++ inst/tests/tests.Rraw | 19 +++++++++++++------ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 74a4b6e1c..00f955c37 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -4,7 +4,6 @@ Title: Extension of `data.frame` Depends: R (>= 3.1.0) Imports: methods Suggests: bit64 (>= 4.0.0), bit (>= 4.0.4), curl, R.utils, xts, nanotime, zoo (>= 1.8-1), yaml, knitr, rmarkdown, markdown -SystemRequirements: zlib 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. License: MPL-2.0 | file LICENSE URL: https://r-datatable.com, https://Rdatatable.gitlab.io/data.table, https://github.com/Rdatatable/data.table diff --git a/R/fwrite.R b/R/fwrite.R index c822b0567..54ef04ed0 100644 --- a/R/fwrite.R +++ b/R/fwrite.R @@ -115,3 +115,5 @@ fwrite = function(x, file="", append=FALSE, quote="auto", invisible() } +nozlib = function() identical(.Call(Cdt_zlib_version), "zlib header files were not found when data.table was compiled") + diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index d7ad5a99a..807983d3f 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -69,6 +69,7 @@ if (exists("test.data.table", .GlobalEnv, inherits=FALSE)) { which.first = data.table:::which.first which.last = data.table:::which.last `-.IDate` = data.table:::`-.IDate` + nozlib = data.table:::nozlib # Also, for functions that are masked by other packages, we need to map the data.table one. Or else, # the other package's function would be picked up. As above, we only need to do this because we desire @@ -9887,8 +9888,12 @@ test(1658.421, fwrite(DT, file=f1<-tempfile(fileext=".gz"), verbose=TRUE), NULL, test(1658.422, fwrite(DT, file=f2<-tempfile()), NULL) test(1658.423, file.info(f1)$size < file.info(f2)$size) # 74 < 804 (file.size() isn't available in R 3.1.0) if (test_R.utils) test(1658.43, fread(f1), DT) # use fread to decompress gz (works cross-platform) -fwrite(DT, file=f3<-tempfile(), compress="gzip") # compress to filename not ending .gz -test(1658.44, file.info(f3)$size, file.info(f1)$size) +if (nozlib()) { + test(1658.442, fwrite(DT, file=f3<-tempfile(), compress="gzip"), error="header files were not found at the time data.table was compiled") +} else { + fwrite(DT, file=f3<-tempfile(), compress="gzip") # compress to filename not ending .gz + test(1658.441, file.info(f3)$size, file.info(f1)$size) +} unlink(c(f1,f2,f3)) DT = data.table(a=1:3, b=list(1:4, c(3.14, 100e10), c("foo", "bar", "baz"))) test(1658.45, fwrite(DT), output=c("a,b","1,1|2|3|4","2,3.14|1e+12","3,foo|bar|baz")) @@ -9916,10 +9921,12 @@ test(1658.52, file.info(f1)$size, file.info(f2)$size) unlink(c(f1, f2)) # compression error -5 due to only 3 bytes (bom) in first block; #3599 -DT = data.table(l=letters, n=1:26) -test(1658.53, fwrite(DT, file=f<-tempfile(fileext=".gz"), bom=TRUE, col.names=FALSE), NULL) -if (test_R.utils) test(1658.54, fread(f), setnames(DT,c("V1","V2"))) -unlink(f) +if (!nozlib()) { + DT = data.table(l=letters, n=1:26) + test(1658.53, fwrite(DT, file=f<-tempfile(fileext=".gz"), bom=TRUE, col.names=FALSE), NULL) + if (test_R.utils) test(1658.54, fread(f), setnames(DT,c("V1","V2"))) + unlink(f) +} # complex column support for fwrite, part of #3690 DT = data.table(a=1:3, z=0:2 - (2:0)*1i)