Skip to content
Back to formatted view

Raw Message

Message-ID: <4F2BF9F9.20208@gmail.com>
Date: 2012-02-03T15:15:05Z
From: Duncan Murdoch
Subject: Clear last x entries of R console
In-Reply-To: <1328277636069-4354669.post@n4.nabble.com>

On 12-02-03 9:00 AM, angliski_jigit wrote:
> Hi All,
>
> I am trying to build in a progress-tracker into my loops that let me have a
> sense of their progress. I'd like to be able to output to screen a series of
> periods "...." etc. for each completion of the loop, but I<don't>  want to
> build a pyramid, e.g.
> .
> ..
> ...
> ....
> etc. So I need to be able to delete<the last line>  of the console entry to
> accomplish this. There are commands to erase the whole console, but that's
> not what I want either; ideally, the command would allow me to erase the
> last line or the last x lines.
>

Just don't write out a newline.  E.g.

for (i in 1:10) {
   cat(".")
   flush.console()
   Sys.sleep(1)
}

You can write out a CR using \r if you want to overwrite the previous 
line, e.g.

for (i in 10:0) {
   cat(i, " \r")
   flush.console()
   Sys.sleep(1)
}


Duncan Murdoch