Skip to content

Commit

Permalink
Pass test.data.table(verbose=TRUE)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattdowle committed Sep 6, 2018
1 parent a500a5a commit 659657a
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 29 deletions.
23 changes: 12 additions & 11 deletions CRAN_Release.cmd
Expand Up @@ -12,6 +12,7 @@ q("no")
# Ensure latest version of R otherwise problems with CRAN not finding dependents that depend on latest R
# e.g. mirror may have been disabled in sources.list when upgrading ubuntu

cd ~/GitHub/data.table
rm ./src/*.so
rm ./src/*.o
rm -rf ./data.table.Rcheck
Expand Down Expand Up @@ -76,7 +77,6 @@ grep mkChar.*Scalar *.c
grep alloc.*mkChar *.c
grep Scalar.*mkChar *.c
grep "getAttrib.*mk" *.c # use sym_* in getAttrib calls
grep "PROTECT *( *getAttrib" *.c # attributes are already protected
grep "\"starts\"" *.c --exclude init.c
grep "setAttrib(" *.c # scan all setAttrib calls manually as a double-check
grep "install(" *.c --exclude init.c # TODO: perhaps in future pre-install all constants
Expand All @@ -95,31 +95,32 @@ grep ScalarString *.c
# If a PROTECT is not needed then a comment is added explaining why and including "PROTECT" in the comment to pass this grep
grep allocVector *.c | grep -v PROTECT | grep -v SET_VECTOR_ELT | grep -v setAttrib | grep -v return

cd ~/GitHub/data.table
cd ..
R
cc(clean=TRUE) # to compile with -pedandic. Also use very latest gcc (currently gcc-7) as CRAN does
saf = options()$stringsAsFactors
options(stringsAsFactors=!saf) # check tests (that might be run by user) are insensitive to option, #2718
test.data.table()
q("no")
R CMD build .
R CMD check data.table_1.11.3.tar.gz --as-cran # remove.packages("xml2") first to prevent the 150 URLs in NEWS.md being pinged by --as-cran
R CMD INSTALL data.table_1.11.3.tar.gz
R
require(data.table)
test.data.table()
test.data.table(verbose=TRUE) # since main.R no longer tests verbose mode
gctorture2(step=50)
system.time(test.data.table()) # apx 75min
R CMD check data.table_1.11.5.tar.gz --as-cran # remove.packages("xml2") first to prevent the 150 URLs in NEWS.md being pinged by --as-cran
R CMD INSTALL data.table_1.11.5.tar.gz

# Test C locale doesn't break test suite (#2771)
echo LC_ALL=C > ~/.Renviron
R
Sys.getlocale()=="C"
q("no")
R CMD check data.table_1.11.3.tar.gz
R CMD check data.table_1.11.5.tar.gz
rm ~/.Renviron

R
require(data.table)
test.data.table()
test.data.table(verbose=TRUE) # since main.R no longer tests verbose mode
gctorture2(step=50)
system.time(test.data.table()) # apx 75min

# Upload to win-builder: release, dev & old-release


Expand Down
2 changes: 1 addition & 1 deletion R/fread.R
@@ -1,5 +1,5 @@

fread <- function(input="",file=NULL,text=NULL,cmd=NULL,sep="auto",sep2="auto",dec=".",quote="\"",nrows=Inf,header="auto",na.strings=getOption("datatable.na.strings","NA"),stringsAsFactors=FALSE,verbose=getOption("datatable.verbose",FALSE),skip="__auto__",select=NULL,drop=NULL,colClasses=NULL,integer64=getOption("datatable.integer64","integer64"), col.names, check.names=FALSE, encoding="unknown", strip.white=TRUE, fill=FALSE, blank.lines.skip=FALSE, key=NULL, index=NULL, showProgress=getOption("datatable.showProgress",interactive()), data.table=getOption("datatable.fread.datatable",TRUE), nThread=getDTthreads(), logical01=getOption("datatable.logical01", FALSE), autostart=NA)
fread <- function(input="",file=NULL,text=NULL,cmd=NULL,sep="auto",sep2="auto",dec=".",quote="\"",nrows=Inf,header="auto",na.strings=getOption("datatable.na.strings","NA"),stringsAsFactors=FALSE,verbose=getOption("datatable.verbose",FALSE),skip="__auto__",select=NULL,drop=NULL,colClasses=NULL,integer64=getOption("datatable.integer64","integer64"), col.names, check.names=FALSE, encoding="unknown", strip.white=TRUE, fill=FALSE, blank.lines.skip=FALSE, key=NULL, index=NULL, showProgress=getOption("datatable.showProgress",interactive()), data.table=getOption("datatable.fread.datatable",TRUE), nThread=getDTthreads(verbose), logical01=getOption("datatable.logical01", FALSE), autostart=NA)
{
if (missing(input)+is.null(file)+is.null(text)+is.null(cmd) < 3L) stop("Used more than one of the arguments input=, file=, text= and cmd=.")
input_has_vars = length(all.vars(substitute(input)))>0L # see news for v1.11.6
Expand Down
2 changes: 1 addition & 1 deletion R/fwrite.R
Expand Up @@ -5,7 +5,7 @@ fwrite <- function(x, file="", append=FALSE, quote="auto",
logical01=getOption("datatable.logical01", FALSE), # due to change to TRUE; see NEWS
logicalAsInt=logical01,
dateTimeAs = c("ISO","squash","epoch","write.csv"),
buffMB=8, nThread=getDTthreads(),
buffMB=8, nThread=getDTthreads(verbose),
showProgress=getOption("datatable.showProgress", interactive()),
verbose=getOption("datatable.verbose", FALSE)) {
isLOGICAL = function(x) isTRUE(x) || identical(FALSE, x) # it seems there is no isFALSE in R?
Expand Down
4 changes: 2 additions & 2 deletions R/test.data.table.R
Expand Up @@ -61,9 +61,9 @@ compactprint <- function(DT, topn=2L) {
" Types=", makeString(substring(sapply(DT, typeof), 1L, 3L)),
" Classes=", makeString(tt), "]")
if (nrow(DT)) {
print(copy(DT)[,(cn):=""], topn=topn)
print(copy(DT)[,(cn):="",verbose=FALSE], topn=topn, class=FALSE)
} else {
print(DT) # "Empty data.table (0 rows) of <ncol> columns ...
print(DT, class=FALSE) # "Empty data.table (0 rows) of <ncol> columns ...
if (ncol(DT)) cat(cn,"\n")
}
invisible()
Expand Down
26 changes: 14 additions & 12 deletions inst/tests/tests.Rraw
Expand Up @@ -2329,7 +2329,7 @@ test(867, names(ans2<-DT[,list(name1=sum(v),name2=sum(w)),by="a,b"]), c("a","b",
test(868, ans1, ans2)
# and related to setnames, too
DT = data.table(a=1:3,b=1:6,key="a")
test(869, DT[J(2,42,84),print(.SD),by=.EACHI], output=c(" b", "1: 2", "2: 5", "Empty data.table (0 rows) of 3 cols: a,V2,V3"))
test(869, DT[J(2,42,84),print(.SD),by=.EACHI], output=" b\n.*1.*2\n2:.*5.*Empty data.table.*of 3 cols: a,V2,V3") # .* for when verbose mode

# Test setnames with duplicate colnames
DT = data.table(a=1:3,b=4:6,b=7:9)
Expand Down Expand Up @@ -2416,7 +2416,7 @@ for (ne in seq_along(eols)) {
headDT = head(DT,nr)[,seq_len(if (nc==0) ncol(DT) else nc),with=FALSE]
if (nr==0) for (j in seq_len(ncol(headDT))) set(headDT,j=j,value=logical()) # when read back in empty cols are the lowest type (logical)
f = tempfile()
lines = capture.output(fwrite(headDT))
lines = capture.output(fwrite(headDT, verbose=FALSE))
cat(paste(lines,collapse=eol), file=f, sep="") # so last line abruptly ends (missing last eol) to test that, otherwise could just pass eol to fwrite
# on unix we simulate Windows too. On Windows \n will write \r\n (and \r\n will write \r\r\n)
testIDtail = nr/100 + nc/1000 + ne/10000
Expand Down Expand Up @@ -9145,8 +9145,6 @@ DT = data.table(A=c(2L,NA,3L), B=c(NA,4:5))
test(1658.23, fwrite(DT), output='A,B\n2,\n,4\n3,5')
test(1658.24, fwrite(DT, na="NA", verbose=TRUE), output='Writing column names.*"A","B".*2,NA\nNA,4\n3,5')

options(oldverbose)

# wrong argument types
test(1658.23, fwrite(ok_dt, 1), error="is.character\\(file\\).*not TRUE")
test(1658.24, fwrite(ok_dt, quote=123), error="identical\\(quote.*auto.*FALSE.*TRUE")
Expand All @@ -9161,12 +9159,14 @@ test(1658.28, fwrite(data.table(NULL)), NULL, warning="Nothing to write")
test(1658.29, fwrite(data.table(id=c("A","B","C"), v=c(1.1,0.0,9.9))), output="id,v\nA,1.1\nB,0\nC,9.9")

# logical NA as "NA" when logical01=TRUE, instead of the default na="" which writes all types including <NA> in character column as ,, consistently.
test(1658.30, fwrite(data.table(id=1:3,bool=c(TRUE,NA,FALSE)),na="NA",logical01=TRUE), output="\"id\",\"bool\"\n1,1\n2,NA\n3,0")
test(1658.31, fwrite(data.table(id=1:3,bool=c(TRUE,NA,FALSE)),na="NA",logical01=TRUE), output="\"id\",\"bool\"\n1,1\n2,NA\n3,0")

# POSIXct
test(1658.31, fwrite(data.table(D = as.POSIXct(seq.Date(as.Date("2038-01-19"), as.Date("2038-01-20"), by = "day")))),
test(1658.32, fwrite(data.table(D = as.POSIXct(seq.Date(as.Date("2038-01-19"), as.Date("2038-01-20"), by = "day")))),
output="D\n2038-01-19T00:00:00Z\n2038-01-20T00:00:00Z")

options(oldverbose)

## End fwrite tests

# tests for #679, inrange(), FR #707
Expand Down Expand Up @@ -10350,9 +10350,9 @@ if (test_bit64) {

# for completeness, added test for NA problem to close #1837.
DT = data.table(x=NA)
test(1751.1, capture.output(fwrite(DT)), c("x",""))
test(1751.2, capture.output(fwrite(DT,na="")), c("x",""))
test(1751.3, capture.output(fwrite(DT,na="NA")), c("\"x\"","NA"))
test(1751.1, capture.output(fwrite(DT, verbose=FALSE)), c("x",""))
test(1751.2, capture.output(fwrite(DT,na="",verbose=FALSE)), c("x",""))
test(1751.3, capture.output(fwrite(DT,na="NA",verbose=FALSE)), c("\"x\"","NA"))
test(1751.4, fread({fwrite(DT, f<-tempfile());f}), DT) # the important thing
unlink(f)

Expand Down Expand Up @@ -11656,7 +11656,7 @@ test(1891.4, fread("A,B,C\n1,foo,bar\n2", fill=TRUE, na.strings="NA"), data.tabl
# preserving "" and NA_character_, #2214
DT = data.table(chr = c(NA, "", "a"), num = c(NA, NA, 2L))
test(1892.1, fread({fwrite(DT,f<-tempfile());f}, na.strings=""), DT); unlink(f)
test(1892.2, capture.output(fwrite(DT)), c("chr,num", ",", "\"\"," , "a,2"))
test(1892.2, capture.output(fwrite(DT, verbose=FALSE)), c("chr,num", ",", "\"\"," , "a,2"))
test(1892.3, fread('A,B\n1,"foo"\n2,\n3,""\n', na.strings="")$B, c("foo", NA, "")) # for issue #2217

# print(DT) should print NA in character columns using <NA> like base R to distinguish from "" and "NA"
Expand Down Expand Up @@ -12056,8 +12056,10 @@ test(1915, fread(str, select = c(5, 1, 3)),
Petal.Length = c(1.4, 1.4, 1.3, 1.5, 1.4)))

# unit tests for #2169 which was already fixed in ec05f8b/src/fwrite.c#L59
test(1916.1, fwrite(data.table(foo = c(NA, TRUE, FALSE)), logical01 = TRUE, na = 'EMPTY'), output=c("\"foo\"","EMPTY","1","0")) # this might need to be changed after #2964 will be solved
test(1916.2, fwrite(data.table(foo = c(NA, TRUE, FALSE)), logical01 = TRUE), output=c("foo","","1","0"))
test(1916.1, fwrite(data.table(foo=c(NA, TRUE, FALSE)), logical01=TRUE, na='EMPTY', verbose=FALSE),
output=c("\"foo\"","EMPTY","1","0")) # this might need to be changed after #2964 will be solved
test(1916.2, fwrite(data.table(foo=c(NA, TRUE, FALSE)), logical01=TRUE, verbose=FALSE),
output=c("foo","","1","0"))

# #732 prefixes i., x. works during join and by=.EACHI
dta <- data.table(idx=1:3, vala=4:6, key="idx")
Expand Down
2 changes: 1 addition & 1 deletion man/fread.Rd
Expand Up @@ -21,7 +21,7 @@ strip.white=TRUE, fill=FALSE, blank.lines.skip=FALSE,
key=NULL, index=NULL,
showProgress=getOption("datatable.showProgress", interactive()),
data.table=getOption("datatable.fread.datatable", TRUE),
nThread=getDTthreads(),
nThread=getDTthreads(verbose),
logical01=getOption("datatable.logical01", FALSE), # due to change to TRUE; see NEWS
autostart=NA
)
Expand Down
2 changes: 1 addition & 1 deletion man/fwrite.Rd
Expand Up @@ -15,7 +15,7 @@ fwrite(x, file = "", append = FALSE, quote = "auto",
logical01 = getOption("datatable.logical01", FALSE), # due to change to TRUE; see NEWS
logicalAsInt = logical01, # deprecated
dateTimeAs = c("ISO","squash","epoch","write.csv"),
buffMB = 8L, nThread = getDTthreads(),
buffMB = 8L, nThread = getDTthreads(verbose),
showProgress = getOption("datatable.showProgress", interactive()),
verbose = getOption("datatable.verbose", FALSE))
}
Expand Down

0 comments on commit 659657a

Please sign in to comment.