diff --git a/R/setkey.R b/R/setkey.R index b50cb8da90..ad3c81500a 100644 --- a/R/setkey.R +++ b/R/setkey.R @@ -161,7 +161,7 @@ is.sorted = function(x, by=NULL) { } ORDERING_TYPES = c('logical', 'integer', 'double', 'complex', 'character') -forderv = function(x, by=seq_along(x), retGrp=FALSE, sort=TRUE, order=1L, na.last=FALSE) +forderv = function(x, by=seq_along(x), retGrp=FALSE, sort=TRUE, order=1L, na.last=FALSE, verbose=FALSE) { if (is.atomic(x) || is.null(x)) { # including forderv(NULL) which returns error consistent with base::order(NULL), if (!missing(by) && !is.null(by)) stopf("x is a single vector, non-NULL 'by' doesn't make sense") @@ -172,10 +172,10 @@ forderv = function(x, by=seq_along(x), retGrp=FALSE, sort=TRUE, order=1L, na.las if (length(order) == 1L) order = rep(order, length(by)) } order = as.integer(order) # length and contents of order being +1/-1 is checked at C level - .Call(Cforder, x, by, retGrp, sort, order, na.last) # returns integer() if already sorted, regardless of sort=TRUE|FALSE + .Call(Cforder, x, by, retGrp, sort, order, na.last, verbose) # returns integer() if already sorted, regardless of sort=TRUE|FALSE } -forder = function(..., na.last=TRUE, decreasing=FALSE) +forder = function(..., na.last=TRUE, decreasing=FALSE, verbose=FALSE) { sub = substitute(list(...)) tt = vapply_1b(sub, function(x) is.null(x) || (is.symbol(x) && !nzchar(x))) @@ -209,7 +209,7 @@ forder = function(..., na.last=TRUE, decreasing=FALSE) data = eval(sub, parent.frame(), parent.frame()) } stopifnot(isTRUEorFALSE(decreasing)) - o = forderv(data, seq_along(data), sort=TRUE, retGrp=FALSE, order= if (decreasing) -asc else asc, na.last) + o = forderv(data, seq_along(data), sort=TRUE, retGrp=FALSE, order= if (decreasing) -asc else asc, na.last, verbose) if (!length(o) && length(data)>=1L) o = seq_along(data[[1L]]) else o o } diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index f49420b311..03256821a6 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -13934,7 +13934,7 @@ verbose_output = capture.output(x[order(a), .N, verbose = TRUE]) test(1967.69, !any(grepl('forder.c', verbose_output, fixed = TRUE))) test(1967.70, any(grepl('[1] 5', verbose_output, fixed = TRUE))) options('datatable.optimize' = 1L) -test(1967.71, x[order(a), .N, verbose = TRUE], 5L, +test(1967.71, x[order(a), .N, verbose = 2L], 5L, output = "forder.c received 5 rows and 1 column") setkey(x) test(1967.72, x[x, .N, on = 'a', verbose = TRUE], 5L, @@ -15291,7 +15291,7 @@ DT = data.table( B = c("b", "c", "a", "b", "b", "b", "c", "a", "b", "a"), C = c(2L, 3L, 5L, 8L, 6L, 1L, 4L, 9L, 10L, 7L) ) -test(2054, DT[order(C)[1:5], B, verbose=TRUE], c('b', 'b', 'c', 'c', 'a'), +test(2054, DT[order(C)[1:5], B, verbose=2L], c('b', 'b', 'c', 'c', 'a'), output = "forder.c received 10 rows and 1 column") # ITime class should be retained for same methods as IDate, #3628 @@ -15702,7 +15702,7 @@ test(2069.33, DT[DT, on = 'z'], error = "Type 'complex' is not supported for joi # forder verbose message when !isReallyReal Date, #1738 DT = data.table(d=sample(seq(as.Date("2015-01-01"), as.Date("2015-01-05"), by="days"), 20, replace=TRUE)) test(2070.01, typeof(DT$d), "double") -test(2070.02, DT[, .N, keyby=d, verbose=TRUE], output="Column 1.*date.*8 byte double.*no fractions are present.*4 byte integer.*to save space and time") +test(2070.02, DT[, .N, keyby=d, verbose=2L], output="Column 1.*date.*8 byte double.*no fractions are present.*4 byte integer.*to save space and time") # coverage along with switch+default pairing test(2071.01, dcast(data.table(id=1, grp=1, e=expression(1)), id ~ grp, value.var='e'), error="Unsupported column type in fcast val: 'expression'") @@ -16163,16 +16163,16 @@ test(2097.3, DT[J(NA_integer_)], error="Factor columns must join to factor or ch # Fixes: 'Column 2 is length 3 which differs' and 'argument x is missing with no default' DT = data.table(id=INT(3,5,2,4,2), rating=LETTERS[5:1]) groups = c("id", "rating") -test(2098.1, DT[do.call(order, mget(groups)), verbose=TRUE], ans<-data.table(id=INT(2,2,3,4,5), rating=c("A","C","E","B","D")), +test(2098.1, DT[do.call(order, mget(groups)), verbose=2L], ans<-data.table(id=INT(2,2,3,4,5), rating=c("A","C","E","B","D")), output=out<-"forder.c received 5 rows and 2 columns") -test(2098.2, DT[with(DT, do.call(order, mget(groups))), verbose=TRUE], ans, output=out) -test(2098.3, DT[do.call(forder, mget(groups)), verbose=TRUE], ans, output=out) -test(2098.4, DT[with(DT, do.call(forder, mget(groups))), verbose=TRUE], ans, output=out) +test(2098.2, DT[with(DT, do.call(order, mget(groups))), verbose=2L], ans, output=out) +test(2098.3, DT[do.call(forder, mget(groups)), verbose=2L], ans, output=out) +test(2098.4, DT[with(DT, do.call(forder, mget(groups))), verbose=2L], ans, output=out) old = options(datatable.optimize=0L) -test(2098.5, DT[do.call(order, mget(groups)), verbose=TRUE], ans, notOutput="forder.c") -test(2098.6, DT[with(DT, do.call(order, mget(groups))), verbose=TRUE], ans, notOutput="forder.c") -test(2098.7, DT[do.call(forder, mget(groups)), verbose=TRUE], ans, output=out) -test(2098.8, DT[with(DT, do.call(forder, mget(groups))), verbose=TRUE], ans, output=out) +test(2098.5, DT[do.call(order, mget(groups)), verbose=2L], ans, notOutput="forder.c") +test(2098.6, DT[with(DT, do.call(order, mget(groups))), verbose=2L], ans, notOutput="forder.c") +test(2098.7, DT[do.call(forder, mget(groups)), verbose=2L], ans, output=out) +test(2098.8, DT[with(DT, do.call(forder, mget(groups))), verbose=2L], ans, output=out) options(old) # Error in update join when joining on factor, #3559 diff --git a/src/assign.c b/src/assign.c index 0bf47a2044..71dd9efc19 100644 --- a/src/assign.c +++ b/src/assign.c @@ -288,10 +288,11 @@ int checkOverAlloc(SEXP x) } SEXP alloccolwrapper(SEXP dt, SEXP overAllocArg, SEXP verbose) { - if (!IS_TRUE_OR_FALSE(verbose)) - error(_("%s must be TRUE or FALSE"), "verbose"); + if ((!isLogical(verbose) && !isInteger(verbose)) || LENGTH(verbose)!=1 || INTEGER(verbose)[0]==NA_INTEGER) + error(_("verbose option must be length 1 non-NA logical or integer")); + bool bverbose = INTEGER(verbose)[0]; int overAlloc = checkOverAlloc(overAllocArg); - SEXP ans = PROTECT(alloccol(dt, length(dt)+overAlloc, LOGICAL(verbose)[0])); + SEXP ans = PROTECT(alloccol(dt, length(dt)+overAlloc, bverbose)); for(R_len_t i = 0; i < LENGTH(ans); i++) { // clear names; also excluded by copyMostAttrib(). Primarily for data.table and as.data.table, but added here centrally (see #103). diff --git a/src/bmerge.c b/src/bmerge.c index 1011c84aab..485ea6d0b4 100644 --- a/src/bmerge.c +++ b/src/bmerge.c @@ -166,7 +166,7 @@ SEXP bmerge(SEXP idt, SEXP xdt, SEXP icolsArg, SEXP xcolsArg, SEXP isorted, SEXP SEXP order = PROTECT(allocVector(INTSXP, length(icolsArg))); protecti++; for (int j=0; j=2 ? GetVerbose()-1L : INTEGER(verboseArg)[0] ; if (!isNewList(DT)) { if (!isVectorAtomic(DT))