How to create a dynamic progress bar in R?

2

To track the processing status in my routines, I use the progress bars of the pbapply package, but I have not found a dynamic way to track more than one process. To illustrate the problem I considered a list containing three elements of different dimensions and that you want to join them taking into account the element in common between them (ID):

 lista<-list(A=data.frame(ID=1:100, Med=rnorm(100,50,100)),
        B=data.frame(ID=1:50, Med=rnorm(100,50,50)),
        C=data.frame(ID=51:100, Med=rnorm(100,50,25)))

 result<-data.frame(ID=1:100,matrix(NA,nrow = 100,ncol = length(lista)))

 for(t in 1:length(lista)){
     local<-dim(lista[[t]])[1]
     for(t2 in 1:local){
         posilocal<-which(result$ID==lista[[t]]$ID[t2])
         result[posilocal,(t+1)]<-lista[[t]]$Med[t2]
     }
  }

How can I create a progress bar that shows the status of the process, considering the evolution of t and t2?

    
asked by anonymous 20.03.2016 / 19:27

1 answer

1

Not ideal, but you can try to do so by using the progress package.

library(progress)
total <- sum(sapply(lista, function(x) dim(x)[1]))
pb <- progress_bar$new(total = total)
for(t in 1:length(lista)){
  local<-dim(lista[[t]])[1]
  for(t2 in 1:local){
    posilocal<-which(result$ID==lista[[t]]$ID[t2])
    result[posilocal,(t+1)]<-lista[[t]]$Med[t2]
    Sys.sleep(3/100)
    pb$tick()
  }
}

First calculate the total size of the loop and then make a slash that traverses it that way.

It seems to be more complicated to put a bar that appears for each process. This is a limitation of RStudio from what I understand. Reading this discussion can help you understand. It looks like the support for multiple slashes is in the plans of the progress package.

    
21.03.2016 / 22:08