Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Progress bar on while loop in r studio

Tags:

r

progress

I would like to see a progress bar while loop is running. I have a data set with 300,000 variables and takes forever. I would like to use a function or package like 'progress' to show how long the loop will take. With the code below is this possible.

           i <- 1
           while (i <= nrow(df)) {
           if (is.na.data.frame(df$case_no[i]))
           df$case_no[i] <- df$case_number[i]
            i <- i + 1
            }
like image 358
Don Mufasa Avatar asked Oct 18 '25 23:10

Don Mufasa


1 Answers

Can do like this

x <- rep(x = NA, times = 100)

pb <- txtProgressBar(0, length(x), style = 3)
for(i in 1:length(x)) {
   setTxtProgressBar(pb, i)
   x[i] 
   Sys.sleep(time = 1)
 }
close(pb)
like image 192
Aleh Avatar answered Oct 20 '25 13:10

Aleh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!