I recently food a way to implement a progress bar in a for loop. (cf ref) An implementation could be :
size = 200
pb <- winProgressBar(title="Progress Bar", label="0% done", min=0, max=100, initial=0)
for(i in 1:size){
Sys.sleep(0.1)
# Progress Bar
info <- sprintf("%d%% done", round((i/size)*100))
setWinProgressBar(pb, i/size*100, label=info)
}
close(pb)
In order to avoid the usage of size at the beginning of the loop how can I one have a variable that would detect the total length of the iterator of the loop. So that the code would be :
pb <- winProgressBar(title="Progress Bar", label="0% done", min=0, max=100, initial=0)
for(i in 1:200){
Sys.sleep(0.1)
# Progress Bar
size = ... # What to do ?
info <- sprintf("%d%% done", round((i/size)*100))
setWinProgressBar(pb, i/size*100, label=info)
}
close(pb)
I am aware that it will add calculus in the for loop it would just make it easy to implement in several loops without having to change their structure.
Thanks !!
Romain