覆盖R控制台中的电流输出 [英] Overwrite current output in the R console

查看:167
本文介绍了覆盖R控制台中的电流输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在玩R函数txtProgressBar()。我如何劫持该功能覆盖控制台中的当前输出的能力?



进度条更新如下:

 >一些R函数
============

/ p>

 >一些R函数
======================

NOT

 >一些R函数
============
====================== $ b $例如,如何编写将在控制台中显示当前时间的函数:

$ b

$ b


$ b

 >一些R函数
13:01

变为

 >一些R函数
13:02

NOT

 >一些R函数
13:01
13:01
13:01
13:01
13:02
13:02
13 :02
13:02


解决方案

似乎工作:

  while(1){
cat('\b\b\b\\ \\ b \b \b',format(Sys.time(),'%​​H:%M'))
flush.console()
}

有什么理由这可能是个坏主意吗?



/ edit:even更好(感谢@Greg Snow):

  while(1){
cat('\r',format (Sys.time(),'%​​H:%M:%S'))
flush.console()
}


I have been playing around with the R function txtProgressBar(). How can I hijack the function's ability to overwrite the current output in the console?

i.e. the progress bar updates like this:

> some R function
============

becomes

> some R function
========================

NOT

> some R function
============
========================

For example, how do I write function that will display the current time in the console:

> some R function
13:01

becomes

> some R function
13:02

NOT

> some R function
13:01
13:01
13:01
13:01
13:02
13:02
13:02
13:02

解决方案

This program seems to work:

while (1) {
cat('\b\b\b\b\b\b',format(Sys.time(),'%H:%M'))
flush.console() 
}

Are there any reasons this might be a bad idea?

/edit: even better (thanks @Greg Snow):

while (1) {
cat('\r',format(Sys.time(),'%H:%M:%S'))
flush.console() 
}

这篇关于覆盖R控制台中的电流输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆