[英]Is it possible to retrieve the console output history in RStudio?
The title pretty much says it all.标题基本概括了所有内容。
I left a process running overnight and used the tictoc
package to measure the duration of it.我让一个进程在一夜之间运行,并使用
tictoc
package 来测量它的持续时间。
When I checked back this morning, I read the output then cleared the console as I always do (muscle memory) to keep things tidy.今天早上回来查看时,我阅读了 output 然后像往常一样清除控制台(肌肉记忆)以保持整洁。
Even though I remember the duration, I would like to share the details of the output with a colleague and rather than running the process again (it took a long time), I wonder if it is possible to retrieve just the output of the console.尽管我记得持续时间,但我想与同事分享 output 的详细信息,而不是再次运行该过程(花了很长时间),我想知道是否可以仅检索控制台的 output。
There don't appear to be any similar questions on Stack Overflow, so I decided to pose one. Stack Overflow 上似乎没有任何类似的问题,所以我决定提出一个。
I am aware that it is possible to retrieve one's own history ( history()
) but that only focuses on inputs whereas I am looking for outputs .我知道可以检索自己的历史(
history()
),但只关注输入,而我正在寻找输出。
Additional detail:附加细节:
zx8754's answer is good, although it only works for the previous result, whereas I need something that looks further back. zx8754 的回答很好,虽然它只适用于之前的结果,而我需要一些更远的东西。
Since clearing the console, I have run several commands, meaning that .Last.value
won't work in this case.自从清除控制台以来,我已经运行了几个命令,这意味着
.Last.value
在这种情况下不起作用。 Is there an approach that looks further back than the most recent output?有没有比最近的 output 更远的方法?
Looks like .Last.value
works, example:看起来
.Last.value
有效,例如:
library(tictoc)
## Timing multiple steps
tic("step 1")
print("Do something...")
Sys.sleep(1)
toc()
# step 1: 1.02 sec elapsed
# Press Ctrl+L to clear console, then
.Last.value
# $tic
# elapsed
# 239407.9
#
# $toc
# elapsed
# 239408.9
#
# $msg
# [1] "step 1"
Print out is not the same, but we can re-construct if needed:打印出来的就不一样了,但是如果需要我们可以重新构造:
x <- .Last.value
paste0(x$msg, ": ", prettyNum(x$toc - x$tic), " sec elapsed")
# [1] "step 1: 1.02 sec elapsed"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.