Skip to content

Commit a0692af

Browse files
committed
only print progress if ngrp>1
1 parent 3b2812b commit a0692af

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/dogroups.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,7 @@ SEXP dogroups(SEXP dt, SEXP dtcols, SEXP groups, SEXP grpcols, SEXP jiscols, SEX
7070
SEXP ans=NULL, jval, thiscol, BY, N, I, GRP, iSD, xSD, rownames, s, RHS, target, source;
7171
Rboolean wasvector, firstalloc=FALSE, NullWarnDone=FALSE;
7272
const bool verbose = LOGICAL(verboseArg)[0]==1;
73-
const bool showProgress = LOGICAL(showProgressArg)[0]==1;
7473
double tstart=0, tblock[10]={0}; int nblock[10]={0}; // For verbose printing, tstart is updated each block
75-
double startTime = (showProgress) ? wallclock() : 0; // For progress printing, startTime is set at the beginning
76-
double nextTime = (showProgress) ? startTime+3 : 0; // wait 3 seconds before printing progress
7774
bool hasPrinted = false;
7875

7976
if (!isInteger(order)) internal_error(__func__, "order not integer vector"); // # nocov
@@ -89,6 +86,10 @@ SEXP dogroups(SEXP dt, SEXP dtcols, SEXP groups, SEXP grpcols, SEXP jiscols, SEX
8986
// fix for longstanding FR/bug, #495. E.g., DT[, c(sum(v1), lapply(.SD, mean)), by=grp, .SDcols=v2:v3] resulted in error.. the idea is, 1) we create .SDall, which is normally == .SD. But if extra vars are detected in jexp other than .SD, then .SD becomes a shallow copy of .SDall with only .SDcols in .SD. Since internally, we don't make a copy, changing .SDall will reflect in .SD. Hopefully this'll workout :-).
9087
SEXP SDall = PROTECT(findVar(install(".SDall"), env)); nprotect++; // PROTECT for rchk
9188
SEXP SD = PROTECT(findVar(install(".SD"), env)); nprotect++;
89+
90+
const bool showProgress = LOGICAL(showProgressArg)[0]==1 && ngrp > 1; // showProgress only if more than 1 group
91+
double startTime = (showProgress) ? wallclock() : 0; // For progress printing, startTime is set at the beginning
92+
double nextTime = (showProgress) ? startTime+3 : 0; // wait 3 seconds before printing progress
9293

9394
defineVar(sym_BY, BY = PROTECT(allocVector(VECSXP, ngrpcols)), env); nprotect++; // PROTECT for rchk
9495
SEXP bynames = PROTECT(allocVector(STRSXP, ngrpcols)); nprotect++; // TO DO: do we really need bynames, can we assign names afterwards in one step?

0 commit comments

Comments
 (0)