[R] for loop 運行進度顯示

  When processing data using for loop, you would want to know the process rate. You can use print, cat or txtProgressBar.
  print and cat are very similar, you can print out what you want to know with both, but with cat, you can use \r to print out the process rate in the same line, making the console more tidy. txtProgressBar is like a progress bar, but you can't use it to print out other messages you want to know (such as data value). The three kinds of code can be seen below.

在資料處理時,
當處理資料量特別大時,
會需要瞭解到資料處理的進度。

第一種是最簡單的使用print


第二種是使用cat與 \r



最後一種是使用txtProgressBar
會顯示進度條


第一種好處是一路印下來,
錯誤也可以用try catch去印,
紀錄運行的過程。
但是容易洗版。

第二種則只會印在同一行,
不會有洗版現象,
但如果要記錄問題,
就要用print以免被蓋掉。

第三種主要就是不會洗版且像個狀態列,
不過想印出運算結果等等我還是習慣用cat。

沒有留言:

張貼留言