I have been playing around with the R function txtProgressBar(). How can I hijack the function's ability to overwrite the current output in the console?
i.e. the progress bar updates like this:
> some R function
============
becomes
> some R function
========================
NOT
> some R function
============
========================
For example, how do I write function that will display the current time in the console:
> some R function
13:01
becomes
> some R function
13:02
NOT
> some R function
13:01
13:01
13:01
13:01
13:02
13:02
13:02
13:02
I do not think overwriting is possible on the console. There is no backspace escape sequence. The progress bar can be drawn because the cat function will not emit a
cr
unless told to do so.Edit: I was wrong. The backspace character is recognized:
This program seems to work:
Are there any reasons this might be a bad idea?
/edit: even better (thanks @Greg Snow):
Sure you can:
Instead of "\b\b\b\b" you can just use "\r" to go to the beginning of the line and overwrite everything on the line (make sure to still use cat and don't put in a line feed).
Though if you want to display progress it might be better to use winProgressBar (windows only) or tkProgressBar (tcltk package, all platforms) which can be updated with a label in addition to the progress bar.
On windows you can also use the setWindowTitle or setStatusBar functions to put that type of information into the top or bottom of the larger window.