Display a time clock in the R command line

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.

Leave a Comment