如何在 R 中使执行暂停、睡眠、等待 X 秒? [英] How to make execution pause, sleep, wait for X seconds in R?
本文介绍了如何在 R 中使执行暂停、睡眠、等待 X 秒?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将 R 脚本暂停指定的秒数或毫秒数?在许多语言中,有一个 sleep
函数,但 ?sleep
引用一个数据集.而 ?pause
和 ?wait
不存在.
How do you pause an R script for a specified number of seconds or miliseconds? In many languages, there is a sleep
function, but ?sleep
references a data set. And ?pause
and ?wait
don't exist.
预期用途是用于自拍动画.所需的解决方案无需用户输入即可运行.
The intended purpose is for self-timed animations. The desired solution works without asking for user input.
推荐答案
参见help(Sys.sleep)
.
例如,来自?Sys.sleep
testit <- function(x)
{
p1 <- proc.time()
Sys.sleep(x)
proc.time() - p1 # The cpu usage should be negligible
}
testit(3.7)
产量
> testit(3.7)
user system elapsed
0.000 0.000 3.704
这篇关于如何在 R 中使执行暂停、睡眠、等待 X 秒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文