I'd like to write a function that presents to the user a status message that shows something like the time, the percent complete, and the current status of a process. I can handle assembling the message, but I'd like to do something other than just print to the console and have it scroll up, one message after the other. I'd really like the message to change without scrolling like message()
and without any graphics. Is this possible with R?
To display ( or print) a text with R, use either the R-command cat() or print(). Note that in each case, the text is considered by R as a script, so it should be in quotes. Note there is subtle difference between the two commands so type on your prompt help(cat) and help(print) to see the difference.
The stop R function generates an error message and stops executing the current R code.
How about something like this?
for(i in 1:10) { Sys.sleep(0.2) # Dirk says using cat() like this is naughty ;-) #cat(i,"\r") # So you can use message() like this, thanks to Sharpie's # comment to use appendLF=FALSE. message(i,"\r",appendLF=FALSE) flush.console() }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With