在R命令行中显示时钟 [英] Display a time clock in the R command line
问题描述
我想知道是否有一种方法可以在R命令行中显示当前时间,例如在MS DOS中,我们可以使用
提示$ T $ P $ G
在每个提示行中包括时钟。
类似于
options(prompt = paste(format(Sys.time(),%H:%M :%S),>))
可以做到,但随后已修复在设定时间。我不确定如何使它自动更新。
后缀指出正确的方法是选项( prompt = ...)
可以用于此目的。但是他的解决方案添加了常量时间表达式,这不是我们想要的。
函数 taskCallbackManager
剩下的:
R> h<-taskCallbackManager()
R> h $ add(function(expr,value,ok,visible){
+ options( prompt = format(Sys.time(),%H:%M:%S>));
+ return(TRUE)},
+名称= simpleHandler)
[1] simpleHandler
07:25:42> a<-2
07:25:48>
我们注册了一个回调,该回调在每个命令完成后得到评估。这样就可以了。更精美的文档是R开发者网站上的 。
I wonder if there is a way to display the current time in the R command line, like in MS DOS, we can use
Prompt $T $P$G
to include the time clock in every prompt line. Something like
options(prompt=paste(format(Sys.time(), "%H:%M:%S"),"> "))
will do it, but then it is fixed at the time it was set. I'm not sure how to make it update automatically.
Chase points the right way as options("prompt"=...)
can be used for this. But his solutions adds a constant time expression which is not what we want.
The documentation for the function taskCallbackManager
has the rest:
R> h <- taskCallbackManager()
R> h$add(function(expr, value, ok, visible) {
+ options("prompt"=format(Sys.time(), "%H:%M:%S> "));
+ return(TRUE) },
+ name = "simpleHandler")
[1] "simpleHandler"
07:25:42> a <- 2
07:25:48>
We register a callback that gets evaluated after each command completes. That does the trick. More fancy documentation is in this document from the R developer site.
这篇关于在R命令行中显示时钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!