I am writing up some data processing stuff and I wanted to have a concise progress status printing a fraction that updates over time on a single line in the console.
我正在写一些数据处理的东西,我希望有一个简洁的进度状态打印一个分数,在控制台的一行上随时间更新。
To get this done 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 don't quite know how to do it. I know that there is a R text progress bar but for utilities sake I'm looking for a little more control.
保持屏幕清洁,什么不是。我不太清楚怎么做。我知道有一个R文本进度条,但为了实用程序的缘故,我正在寻找更多的控制。
Thanks!
1 个解决方案
#1
I think your best bet is to do exactly what the R text progress bar does, which is "\r
to return to the left margin", as seen in the help file. You'll have to use cat
instead of print
because print
ends with a newline.
我认为你最好的办法就是完成R文本进度条所做的工作,即“\ r \ n返回左边距”,如帮助文件中所示。您必须使用cat而不是print,因为print以换行符结束。
cat("Initiating data processing...\n")
for(sample in 1:length(data)){
cat(sample, length(data), sep="/")
process(data[[sample]])
cat("\r")
}
cat("\n")
#1
I think your best bet is to do exactly what the R text progress bar does, which is "\r
to return to the left margin", as seen in the help file. You'll have to use cat
instead of print
because print
ends with a newline.
我认为你最好的办法就是完成R文本进度条所做的工作,即“\ r \ n返回左边距”,如帮助文件中所示。您必须使用cat而不是print,因为print以换行符结束。
cat("Initiating data processing...\n")
for(sample in 1:length(data)){
cat(sample, length(data), sep="/")
process(data[[sample]])
cat("\r")
}
cat("\n")