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

问题描述 投票:0回答:1

我知道如何使用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始终将此作为提示?

r time clock
1个回答
1
投票

一种选择是在.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")
}

我想你也可以在你的“C:\ Program Files \ R \ R-x.x.x \ etc”中的Rprofile.site中做到这一点。正如@ r2evans所指出的,这似乎是一个坏主意。

© www.soinside.com 2019 - 2024. All rights reserved.