R: Text progress bar in for loop

后端 未结 2 1109
南旧
南旧 2020-12-14 01:49

I have some sample code which contains a for loop and creates some plots like this (my actual data creates several thousands of plots):

xy <- structure(li         


        
2条回答
  •  自闭症患者
    2020-12-14 02:27

    You could write a very simple one on the fly to show percent completed:

    n <- 100
    for (ii in 1:n) {
      cat(paste0(round(ii / n * 100), '% completed'))
      Sys.sleep(.05)
      if (ii == n) cat(': Done')
      else cat('\014')
    }
    # 50% completed
    

    Or one to replicate the text bar:

    n <- 100
    for (ii in 1:n) {
      width <- options()$width
      cat(paste0(rep('=', ii / n * width), collapse = ''))
      Sys.sleep(.05)
      if (ii == n) cat('\014Done')
      else cat('\014')
    }
    # ============================
    

提交回复
热议问题