[R] cat(), Rgui, and support for carriage return \r...
Philippe Grosjean
phgrosjean at sciviews.org
Sun Mar 19 12:06:09 CET 2006
How did you look in the archives? It is already a dozen times that I answer:
> library(svMisc) # SciViews bundle
> ?progress
on this list for a similar question.
If you do:
> RSiteSearch("progress")
you have hundreds of results, with several items in the first page that
point to this function.
(actually, this function repeatedly uses \b which works on all system
tested (Linux console, RTerm, RGui, SciViews-R).
Best,
Philippe Grosjean
Duncan Murdoch wrote:
> On 3/17/2006 9:44 AM, Jeffrey Racine wrote:
>
>>Hi, and thanks in advance for your time.
>>
>>Background - I am working on a package and wish to have a routine's
>>progress reported. The routine can take some time, and I would like to
>>inform the user about the routine's progress. I have scoured the
>>archives but to no avail, so would like to solicit input from this list.
>>
>>I am successfully using
>>
>>cat("\rBootstrap replication ", i, " of ", boot.num,)
>>flush.console() # To flush stdout on windows systems
>>
>>which works as expected on *NIX systems and using Rterm under windows.
>>However, under Rgui the carriage return \r is ignored, and I certainly
>>don't want to use the newline escape sequence \n. Under Rgui it appears
>>as
>>
>>Bootstrap replication 1 of 399Bootstrap replication 2 of 399Bootstrap...
>>
>>but I want it to function properly if at all possible.
>>
>>My question is simply whether there is a portable way to implement this
>>so that it works regardless of the R platform the user may be working
>>on?
>>
>>Many thanks for any/all suggestions.
>
>
> I've just been looking at the source code for this. I think it will be
> relatively easy to make \r in Rgui do a destructive CR (i.e. it will
> return to the start of the line, but clear any existing characters).
> I'll play around a bit and then do that for R-devel.
>
> In the meantime, \b does a destructive backspace, so you can get the
> effect you want with something like this:
>
> msg <- ""
> for (i in 1:1000) {
> cat(rep("\b", nchar(msg)), sep="")
> msg <- paste("Message ", i)
> cat(msg)
> flush.console()
> }
>
> This seems to work in Rgui, Rterm, (and R on Unix, if you get rid of the
> flush.console call).
>
> Duncan Murdoch
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
>
More information about the R-help
mailing list