Description Usage Arguments Details Author(s) Examples
reportLoop
is a nicely packaged progress reporter for your loop. It doesn't require any initialization like txtProgressBar
does; you just drop the thing into your loop and it goes to work.
1 2 3 4 5 6 7 | reportLoop(
x,
max,
label=NA,
waitSeconds=0,
includePB=TRUE
)
|
x |
The current numeric iteration. |
max |
The maximum number of iterations. |
label |
A label for your loop. If |
waitSeconds |
The number of seconds to wait before starting the progress bar. This can be handy for processes that may either finish quickly or take a while to run. Defaults to |
includePB |
Whether to include a progress bar. Defaults to |
By the way, a few quirks of the thing:
It stores two variables in the global environment during execution:
.reportLoopDurationToolsWorkingProgressBarId
.reportLoopDurationToolsMostRecentMaxValue
They get removed when the loop finishes–i.e. when x==max
–so if you terminate your loop before x==max
, they'll still be around. They don't hurt anything, and if you're using a scientific computing IDE, your variable list will probably hide them. But if you happen across them by chance and you're wondering where they come from, that's where.
And speaking of .reportLoopDurationToolsMostRecentMaxValue
, the looper assumes you've started a new loop when you give it an x
that's lower than an x
from a previous loop. So kindly don't have your loop iterators go backwards.
There are a lot of ways to improve this little function, but for now I just need it to report progress for work, and the meeting to report on it's in half an hour. So it'll just have to do for now.
1 2 3 4 5 6 7 8 9 10 | loopLimit <- 10
sleepTime <- 0.25
for(i in 1:loopLimit){
durationTools::reportLoop(i,loopLimit,"Reporting a test loop...")
Sys.sleep(sleepTime)
}
for(i in 1:loopLimit){
durationTools::reportLoop(i,loopLimit,"Reporting another test loop...")
Sys.sleep(sleepTime)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.