I need to process a long list of images using a loop. It takes a considerable time to run everything, and therefore I would like to keep track of the progress.
This is my loop:
files.list <- c("LC82210802013322LGN00_B1.TIF", "LC82210802013322LGN00_B10.TIF", 
"LC82210802013322LGN00_B11.TIF", "LC82210802013322LGN00_B2.TIF", 
"LC82210802013322LGN00_B3.TIF", "LC82210802013322LGN00_B4.TIF", 
"LC82210802013322LGN00_B5.TIF", "LC82210802013322LGN00_B6.TIF", 
"LC82210802013322LGN00_B7.TIF", "LC82210802013322LGN00_B8.TIF", 
"LC82210802013322LGN00_B9.TIF", "LC82210802013322LGN00_BQA.TIF", 
"LC82210802013354LGN00_B1.TIF", "LC82210802013354LGN00_B10.TIF", 
"LC82210802013354LGN00_B11.TIF", "LC82210802013354LGN00_B2.TIF", 
"LC82210802013354LGN00_B3.TIF", "LC82210802013354LGN00_B4.TIF", 
"LC82210802013354LGN00_B5.TIF", "LC82210802013354LGN00_B6.TIF", 
"LC82210802013354LGN00_B7.TIF", "LC82210802013354LGN00_B8.TIF", 
"LC82210802013354LGN00_B9.TIF", "LC82210802013354LGN00_BQA.TIF", 
"LC82210802014021LGN00_B1.TIF", "LC82210802014021LGN00_B10.TIF", 
"LC82210802014021LGN00_B11.TIF", "LC82210802014021LGN00_B2.TIF", 
"LC82210802014021LGN00_B3.TIF", "LC82210802014021LGN00_B4.TIF", 
"LC82210802014021LGN00_B5.TIF", "LC82210802014021LGN00_B6.TIF", 
"LC82210802014021LGN00_B7.TIF", "LC82210802014021LGN00_B8.TIF", 
"LC82210802014021LGN00_B9.TIF", "LC82210802014021LGN00_BQA.TIF", 
"LC82210802014037LGN00_B1.TIF", "LC82210802014037LGN00_B10.TIF", 
"LC82210802014037LGN00_B11.TIF", "LC82210802014037LGN00_B2.TIF", 
"LC82210802014037LGN00_B3.TIF", "LC82210802014037LGN00_B4.TIF", 
"LC82210802014037LGN00_B5.TIF", "LC82210802014037LGN00_B6.TIF", 
"LC82210802014037LGN00_B7.TIF", "LC82210802014037LGN00_B8.TIF", 
"LC82210802014037LGN00_B9.TIF", "LC82210802014037LGN00_BQA.TIF", 
"LC82210802014085LGN00_B1.TIF", "LC82210802014085LGN00_B10.TIF", 
"LC82210802014085LGN00_B11.TIF", "LC82210802014085LGN00_B2.TIF", 
"LC82210802014085LGN00_B3.TIF", "LC82210802014085LGN00_B4.TIF", 
"LC82210802014085LGN00_B5.TIF", "LC82210802014085LGN00_B6.TIF", 
"LC82210802014085LGN00_B7.TIF", "LC82210802014085LGN00_B8.TIF", 
"LC82210802014085LGN00_B9.TIF", "LC82210802014085LGN00_BQA.TIF"
)
for (x in files.list) { #loop over files
  # Tell about progress
  cat('Processing image', x, 'of', length(files.list),'\n')
}
Of course, instead of showing the name of the file, I would like to show the index of the current file in the context of the length of the entire list.
I really need the names of the files within the loop, because I need to load and save a new version of each one of them.
Any ideas? Thanks in advance.
for (x in 1:length(files.list)) { #loop over files
 # doing something on x-th file =>      files.list[x]
  # Tell about progress
  cat('Processing image', x, 'of', length(reproj),'\n')
}
                        for (i in 1:length(files.list)) {
  x <- files.list[i]
  # do stuff with x
  message('Processing image ', i, ' of ', length(files.list))
}
                        You can use system window progress bar as under:
 # put this before start of loop
    total = length of your loop
    # put this before closing braces of loop
    pb <- winProgressBar(title = "progress bar", min = 0, max =total , width = 300)
          Sys.sleep(0.1)
# Here i is loop itrator
          setWinProgressBar(pb, i, title=paste( round(i/total*100, 0),"% done"))
    # put this after closing braces of loop
    close(pb)
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With