How do you create a progress bar when using the “foreach()” function in R?

前端 未结 7 1275
青春惊慌失措
青春惊慌失措 2020-11-28 03:41

there are some informative posts on how to create a counter for loops in an R program. However, how do you create a similar function when using the parallelized version wit

7条回答
  •  Happy的楠姐
    2020-11-28 04:12

    You save the start time with Sys.time() before the loop. Loop over rows or columns or something which you know the total of. Then, inside the loop you can calculate the time ran so far (see difftime), percentage complete, speed and estimated time left. Each process can print those progress lines with the message function. You'll get an output something like

    1/1000 complete @ 1 items/s, ETA: 00:00:45
    2/1000 complete @ 1 items/s, ETA: 00:00:44
    

    Obviously the looping order will greatly affect how well this works. Don't know about foreach but with multicore's mclapply you'd get good results using mc.preschedule=FALSE, which means that items are allocated to processes one-by-one in order as previous items complete.

提交回复
热议问题