Clear last x entries of R console

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Clear last x entries of R console

angliski_jigit
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.

Thanks
Angliski
Reply | Threaded
Open this post in threaded view
|

Re: Clear last x entries of R console

Duncan Murdoch-2
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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Clear last x entries of R console

angliski_jigit
Thanks! I had a quick play with cat() in the command line (e.g. typing cat(".")) and didn't seem to help because it just sent me to a new line; I see now that when put into a script though cat() is all you need.
Thanks, AJ
Reply | Threaded
Open this post in threaded view
|

Re: Clear last x entries of R console

glsnow
In reply to this post by angliski_jigit
You may want to look at functions like: txtProgressBar, winProgressBar
(windows onnly), or tkProgressBar (tcltk package), rather than
reinventing the wheel.

On Fri, Feb 3, 2012 at 7:00 AM, angliski_jigit
<[hidden email]> 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.
>
> Thanks
> Angliski
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Clear-last-x-entries-of-R-console-tp4354669p4354669.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



--
--
Gregory (Greg) L. Snow Ph.D.
[hidden email]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.