简体   繁体   English

在 RStudio 控制台中显示时间戳

[英]Showing the timestamp in RStudio console

Simple question: is there a way how I can add a timestamp into the RStudio console?简单的问题:有没有办法在 RStudio 控制台中添加时间戳? Instead of the console only showing this:而不是控制台只显示这个:

>"This is my code"

it would convert this (after executing) into它会将此(执行后)转换为

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

The simplest way is to use Sys.time()最简单的方法是使用Sys.time()

this is my code
Sys.time()

In future RStudio releases it might be possible to assign shortcuts to user scripts.在未来的 RStudio 版本中,可能会为用户脚本分配快捷方式。

Then you might be able to create a function that will execute code and always output whatever statistics you want by pressing ctrl + enter .然后,您可以创建一个函数,该函数将执行代码并通过按ctrl + enter始终输出您想要的任何统计信息。 RStudio Can't guess these stats for everyone, what if I want the end time as well as the start time? RStudio 无法为每个人猜测这些统计数据,如果我想要结束时间和开始时间怎么办? How about the execution time?执行时间如何? RStudio and R are great but yea, sometimes we still have to do stuff ourselves like coding our own darned statistics. 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

You could try the taskCallbackManager - this gets evaluated every time a function is called:您可以尝试使用taskCallbackManager - 每次调用函数时都会对其进行评估:

new_prompt <- taskCallbackManager()

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM