在 R 命令行中永久显示时钟

Permanently display a time clock in the R command line

我知道如何使用

在 R 会话期间添加时间戳
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

this answer所述。

我怎样才能使它成为永久性功能,以便 RStudio 始终将其作为提示?

一个选项是在 ~/ 中有一个 .Rprofile 文件(通常是 windows 中的 "C:/Users/me/Documents"),并在其中添加以下内容。 只要你在控制台上做一些事情,它就会显示时间。

.First <- function(){

   h <- taskCallbackManager()
   h$add(function(expr, value, ok, visible) { 
     options("prompt"=format(Sys.time(), "%H:%M:%S> ")); 
     return(TRUE) }, name = "simpleHandler")
}

我想你可以在 Rprofile.site "C:\Program Files\R\R-x.x.x\etc" 还有。正如@r2evans 所指出的,这似乎是个坏主意。