在 R 中显示状态消息
我想编写一个函数,向用户呈现一条状态消息,显示时间、完成百分比和进程的当前状态等信息。我可以处理组装消息,但我想做的不仅仅是打印到控制台并让它向上滚动,一条消息接着一条消息。我真的希望消息能够改变,而无需像 message()
那样滚动,并且没有任何图形。这可以用 R 实现吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
像这样的事情怎么样?
How about something like this?
utils
包包含txtProgressBar
和更新它的函数,可用于显示进程的完成百分比。有关如何更新的示例,请参阅在调用
txtProgressBar
期间创建的up1
、up2
和up3
函数无需滚动控制台即可处理。The
utils
package contains thetxtProgressBar
and functions for updating it which can be used to show the percent complete of a process.See the
up1
,up2
andup3
functions that are created during a call totxtProgressBar
for examples of how updates are handled without scrolling the console.这里有一些 bling bling 的东西。来自
?tcltk::tkProgressBar
。Here's some bling bling. From
?tcltk::tkProgressBar
.可能有更优雅的方法来做到这一点,但这可以做到这一点:
如果您自动生成消息,您将需要计算要输出多少个 \b 字符以备份正确的数量,但这非常简单。
There may be more elegant ways to do this, but this could do it:
If you're automatically generating your message, you'll need to calculate how many \b characters to output to back up the correct amount, but that's pretty straightforward.