RcppThread icon indicating copy to clipboard operation
RcppThread copied to clipboard

Feature request: Custom ProgressBar/ProgressCounter message

Open tylermorganwall opened this issue 2 years ago • 1 comments

Fiirst off, great package--really enjoy using it.

Right now, the ProgressBar/ProgressCounter classes have the message "Computing: " hard coded in before the progress bar.

class ProgressCounter : public ProgressPrinter {

public:
    //! constructs a progress counter.
    //! @param numIt total number of iterations.
    //! @param printEvery how regularly to print updates (in seconds).
    ProgressCounter(size_t numIt, size_t printEvery) :
        ProgressPrinter(numIt, printEvery)
    {}

private:
    //! prints progress in percent to the R console (+ an estimate of remaining
    //! time).
    void printProgress() {
        if (isDone_)
            return;
        if (it_ == numIt_)
            isDone_ = true;
        std::ostringstream msg;
        msg << "\rComputing: " << progressString();
        Rcout << msg.str();
    }
};

It would be nice to be able to pass a custom string to use in place of that message as part of the constructor, e.g.

class ProgressCounter : public ProgressPrinter {

public:
    //! constructs a progress counter.
    //! @param numIt total number of iterations.
    //! @param printEvery how regularly to print updates (in seconds).
    ProgressCounter(size_t numIt, size_t printEvery, std::string custom_msg = "Computing: ") :
        ProgressPrinter(numIt, printEvery), cmsg(custom_msg)
    {}

private:
    std::string cmsg;
    //! prints progress in percent to the R console (+ an estimate of remaining
    //! time).
    void printProgress() {
        if (isDone_)
            return;
        if (it_ == numIt_)
            isDone_ = true;
        std::ostringstream msg;
        msg << "\r" << cmsg << progressString();
        Rcout << msg.str();
    }
};

The use case is when you have multiple steps of computation with different progress bars, it's nice for the progress bar to show what stage the user is currently in.

tylermorganwall avatar Oct 11 '23 15:10 tylermorganwall

That's a great idea, thanks for the suggestion! I'll try to get to it next week (the coding part should be easy, but reverse dependency testing + CRAN release usually takes a few hours).

tnagler avatar Oct 12 '23 07:10 tnagler