【问题标题】:Showing the timestamp in RStudio console在 RStudio 控制台中显示时间戳
【发布时间】:2020-11-06 13:52:44
【问题描述】:

简单的问题:有没有办法在 RStudio 控制台中添加时间戳?而不是控制台只显示这个:

>"This is my code"

它将(在执行后)转换成

[HH:MM:SS]> "This is my code"
[1] "This is my code"

【问题讨论】:

    标签: r console rstudio


    【解决方案1】:

    最简单的方法是使用Sys.time()

    this is my code
    Sys.time()
    

    在未来的 RStudio 版本中,可能会assign shortcuts to user scripts.

    然后您可能能够创建一个函数,该函数将执行代码并始终通过按ctrl+enter 输出您想要的任何统计信息。 RStudio 无法为每个人猜测这些统计信息,如果我想要结束时间和开始时间怎么办?执行时间如何? RStudio 和 R 很棒,但是是的,有时我们仍然需要自己做一些事情,比如编写我们自己该死的统计数据。

    Kevin UsheySeptember 15, 2015 12:49
    Hi Alain,
    
    Mapping keyboard shortcuts to user scripts is something we have in the pipeline, but we haven't yet completed that work. Stay tuned!
    
    Best,
    Kevin
    

    【讨论】:

    • 嗯,但这意味着始终将系统时间代码添加到您在 R 中运行的任何代码行中。当执行任何代码时,这对于记录任何代码都不是很有帮助,对吧?
    • 好的,谢谢。所以底线没有GUI的内置功能,对吧?我的意思是我会期待这样的事情。它更像是您要设置的全局选项,而不是添加到特定脚本中。
    【解决方案2】:

    您可以尝试taskCallbackManager - 每次调用函数时都会对其进行评估:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-09
      • 1970-01-01
      • 2020-08-12
      • 1970-01-01
      • 2017-06-13
      • 2016-05-19
      相关资源
      最近更新 更多