Jeffrey Racine
2006-Mar-17 14:44 UTC
[R] cat(), Rgui, and support for carriage return \r...
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. -- Jeff -- Professor J. S. Racine Phone: (905) 525 9140 x 23825 Department of Economics FAX: (905) 521-8232 McMaster University e-mail: racinej at mcmaster.ca 1280 Main St. W.,Hamilton, URL: http://www.economics.mcmaster.ca/racine/ Ontario, Canada. L8S 4M4 `The generation of random numbers is too important to be left to
Doran, Harold
2006-Mar-17 14:57 UTC
[R] cat(), Rgui, and support for carriage return \r...
Here is a snip of code I used in a program that was looping for a really long time, maybe this can be helpful. You will need the svMisc package. print(i) progress(i) Sys.sleep(.05) -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Jeffrey Racine Sent: Friday, March 17, 2006 9:45 AM To: r-help at stat.math.ethz.ch Subject: [R] cat(), Rgui, and support for carriage return \r... 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. -- Jeff -- Professor J. S. Racine Phone: (905) 525 9140 x 23825 Department of Economics FAX: (905) 521-8232 McMaster University e-mail: racinej at mcmaster.ca 1280 Main St. W.,Hamilton, URL: http://www.economics.mcmaster.ca/racine/ Ontario, Canada. L8S 4M4 `The generation of random numbers is too important to be left to ______________________________________________ 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
Gabor Grothendieck
2006-Mar-17 15:00 UTC
[R] cat(), Rgui, and support for carriage return \r...
You could try this: eol <- if (Platform$OS.type == "windows") "\n" else "\r" and then use the eol variable in your cat statement. On 3/17/06, Jeffrey Racine <racinej at mcmaster.ca> 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. > > -- Jeff > > -- > Professor J. S. Racine Phone: (905) 525 9140 x 23825 > Department of Economics FAX: (905) 521-8232 > McMaster University e-mail: racinej at mcmaster.ca > 1280 Main St. W.,Hamilton, URL: > http://www.economics.mcmaster.ca/racine/ > Ontario, Canada. L8S 4M4 > > `The generation of random numbers is too important to be left to > > ______________________________________________ > 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 >
Duncan Murdoch
2006-Mar-17 19:39 UTC
[R] cat(), Rgui, and support for carriage return \r...
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.This looks like it would be a useful addition to Rgui to support this. The problem is that on Unix or Rterm, it isn't actually R that does anything, it's the display that handles the CR with no LF. Rgui uses a different mechanism for putting text on the screen, so this would have to be implemented specially. Just out of interest: does the Mac OS X gui handle this like the ascii terminals or like Windows Rgui? Duncan Murdoch
Duncan Murdoch
2006-Mar-18 19:39 UTC
[R] cat(), Rgui, and support for carriage return \r...
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
Apparently Analagous Threads
- Advice wanted on using optim with both continuous and discrete par arguments...
- Help with efficient double sum of max (X_i, Y_i) (X & Y vectors)
- Guidance on step() with large dataset (750K) solicited...
- Trivial formatting typo in summary(lm()) (PR#10480)
- reading a text file with a stray carriage return