Can you print a string in R?

I am writing some data manipulation stuff and I wanted a summary of the execution status to print a part that updates over time on a single line on the console.

To do this I wanted to have something like this

print(Initiating data processing...)
for(sample in 1:length(data)){
   print(paste(sample,length(data),sep="/"))
   process(data[[sample]])
   #Unprint the bottom line in the console ... !!! ... !!!.. ?
}

      

Keeping the screen clean and what not. I am not quite sure how to do this. I know there is an R progress progress bar , but for a utility I am looking for a little more control.

Thank!

+3


source to share


1 answer


I think the best thing to do is what the R-text progress bar does, which is " \r

to go back to the left" as seen in the help file. You should use cat

instead print

because it print

ends with a newline character.



cat("Initiating data processing...\n")
for(sample in 1:length(data)){
   cat(sample, length(data), sep="/")
   process(data[[sample]])
   cat("\r")
}
cat("\n")

      

+6


source







All Articles