-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
duckdb_progress_display <- function(x) { | ||
if (x <= 100) cat(sprintf("\r%3d%%", x)) | ||
if (x >= 100) cat("\r ") | ||
} | ||
|
||
check_progress_display <- function(f) { | ||
if (is.null(f)) return() | ||
if (is.TRUE(f) || isFALSE(f)) return() | ||
if (is.function(f)) { | ||
if (length(formals(f)) > 0) return() | ||
stop("`progress_display` has no argument, expecting at least one.") | ||
} | ||
stop("`progress_display` is not function, expecting either a boolean or function.") | ||
} | ||
|
||
set_progress_display <- function(f) { | ||
check_progress_display(f) | ||
options("duckdb.progress_display" = { | ||
if (isTRUE(progress_display)) { | ||
duckdb_progress_display | ||
} else if (is.function(progress_display)) { | ||
progress_display | ||
} else { | ||
NULL | ||
} | ||
}) | ||
} | ||
|
||
get_progress_display <- function(f) { | ||
getOption("duckdb.progress_display", default = duckdb_progress_display) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#pragma once | ||
|
||
#include "rapi.hpp" | ||
#include "duckdb/common/progress_bar/progress_bar_display.hpp" | ||
#include "duckdb/common/helper.hpp" | ||
|
||
namespace duckdb { | ||
|
||
class RProgressBarDisplay : public ProgressBarDisplay { | ||
public: | ||
RProgressBarDisplay(); | ||
virtual ~RProgressBarDisplay() { | ||
} | ||
|
||
static unique_ptr<ProgressBarDisplay> Create(); | ||
|
||
public: | ||
void Update(double percentage) override; | ||
void Finish() override; | ||
|
||
private: | ||
void Initialize(); | ||
|
||
private: | ||
SEXP progress_callback = R_NilValue; | ||
}; | ||
|
||
} // namespace duckdb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
test_that("progress display", { | ||
|
||
expect_error(check_progress_display(5), "expecting either a boolean or function") | ||
expect_error(check_progress_display(function(){}), "has no argument, expecting at least one") | ||
|
||
expect_null(check_progress_display(function(x){})) | ||
expect_null(check_progress_display(TRUE)) | ||
expect_null(check_progress_display(FALSE)) | ||
expect_null(check_progress_display(NULL)) | ||
|
||
}) |