How do I print a variable inside a for loop to the console in real time, as the loop is running, in R?

后端 未结 2 1733
眼角桃花
眼角桃花 2021-01-04 02:01

I have a loop that takes a long time for each iteration, and I would like to see the progress of it in real time. How do I print a variable inside a for loop to the console

2条回答
  •  佛祖请我去吃肉
    2021-01-04 02:37

    The cat() function allows you to make useful complex statements to keep track of progress in your script

    for(i in 1:10){
      ptm0 <- proc.time()
      Sys.sleep(0.5)  
      ptm1=proc.time() - ptm0
      jnk=as.numeric(ptm1[3])
      cat('\n','It took ', jnk, "seconds to do iteration", i)
    }
    
    >It took  0.49 seconds to do iteration 1
    

提交回复
热议问题