Skip to content

Commit 3990670

Browse files
committed
allow showProgress=INTEGER to set progress bar update time
1 parent e2e0173 commit 3990670

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

R/data.table.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ replace_dot_alias = function(e) {
147147
}
148148
}
149149

150-
"[.data.table" = function(x, i, j, by, keyby, with=TRUE, nomatch=NA, mult="all", roll=FALSE, rollends=if (roll=="nearest") c(TRUE,TRUE) else if (roll>=0.0) c(FALSE,TRUE) else c(TRUE,FALSE), which=FALSE, .SDcols, verbose=getOption("datatable.verbose"), allow.cartesian=getOption("datatable.allow.cartesian"), drop=NULL, on=NULL, env=NULL, showProgress=getOption("datatable.showProgress", interactive()))
150+
"[.data.table" = function(x, i, j, by, keyby, with=TRUE, nomatch=NA, mult="all", roll=FALSE, rollends=if (roll=="nearest") c(TRUE,TRUE) else if (roll>=0.0) c(FALSE,TRUE) else c(TRUE,FALSE), which=FALSE, .SDcols, verbose=getOption("datatable.verbose"), allow.cartesian=getOption("datatable.allow.cartesian"), drop=NULL, on=NULL, env=NULL, showProgress=as.integer(getOption("datatable.showProgress", interactive())))
151151
{
152152
# ..selfcount <<- ..selfcount+1 # in dev, we check no self calls, each of which doubles overhead, or could
153153
# test explicitly if the caller is [.data.table (even stronger test. TO DO.)
@@ -244,7 +244,7 @@ replace_dot_alias = function(e) {
244244
if ((isTRUE(which)||is.na(which)) && !missing(j)) stopf("which==%s (meaning return row numbers) but j is also supplied. Either you need row numbers or the result of j, but only one type of result can be returned.", which)
245245
if (is.null(nomatch) && is.na(which)) stopf("which=NA with nomatch=0|NULL would always return an empty vector. Please change or remove either which or nomatch.")
246246
if (!with && missing(j)) stopf("j must be provided when with=FALSE")
247-
if (!missing(by) && !isTRUEorFALSE(showProgress)) stopf("%s must be TRUE or FALSE", "showProgress")
247+
if (!missing(by) && !is.numeric(showProgress)) stopf("%s must be numeric.", "showProgress")
248248
irows = NULL # Meaning all rows. We avoid creating 1:nrow(x) for efficiency.
249249
notjoin = FALSE
250250
rightcols = leftcols = integer()
@@ -1934,7 +1934,7 @@ replace_dot_alias = function(e) {
19341934
}
19351935
ans = c(g, ans)
19361936
} else {
1937-
ans = .Call(Cdogroups, x, xcols, groups, grpcols, jiscols, xjiscols, grporder, o__, f__, len__, jsub, SDenv, cols, newnames, !missing(on), verbose, showProgress)
1937+
ans = .Call(Cdogroups, x, xcols, groups, grpcols, jiscols, xjiscols, grporder, o__, f__, len__, jsub, SDenv, cols, newnames, !missing(on), verbose, as.integer(showProgress))
19381938
}
19391939
# unlock any locked data.table components of the answer, #4159
19401940
# MAX_DEPTH prevents possible infinite recursion from truly recursive object, #4173

src/dogroups.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,10 @@ SEXP dogroups(SEXP dt, SEXP dtcols, SEXP groups, SEXP grpcols, SEXP jiscols, SEX
8787
SEXP SDall = PROTECT(findVar(install(".SDall"), env)); nprotect++; // PROTECT for rchk
8888
SEXP SD = PROTECT(findVar(install(".SD"), env)); nprotect++;
8989

90-
const bool showProgress = LOGICAL(showProgressArg)[0]==1 && ngrp > 1; // showProgress only if more than 1 group
90+
int updateTime = INTEGER(showProgressArg)[0];
91+
const bool showProgress = updateTime > 0 && ngrp > 1; // showProgress only if more than 1 group
9192
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
93+
double nextTime = (showProgress) ? startTime + MAX(updateTime, 3) : 0; // wait at least 3 seconds before printing progress
9394

9495
defineVar(sym_BY, BY = PROTECT(allocVector(VECSXP, ngrpcols)), env); nprotect++; // PROTECT for rchk
9596
SEXP bynames = PROTECT(allocVector(STRSXP, ngrpcols)); nprotect++; // TO DO: do we really need bynames, can we assign names afterwards in one step?
@@ -456,7 +457,7 @@ SEXP dogroups(SEXP dt, SEXP dtcols, SEXP groups, SEXP grpcols, SEXP jiscols, SEX
456457
Rprintf(_("Processed %d groups out of %d. %.0f%% done. Time elapsed: %ds. ETA: %ds."), i+1, ngrp, 100.0*(i+1)/ngrp, (int)(now-startTime), ETA);
457458
// # nocov end
458459
}
459-
nextTime = now+1;
460+
nextTime = now+updateTime;
460461
hasPrinted = true;
461462
}
462463
ansloc += maxn;

0 commit comments

Comments
 (0)