在R函数中使用Sys.sleep来延迟多个输出 [英] Using Sys.sleep in R function to delay multiple outputs
本文介绍了在R函数中使用Sys.sleep来延迟多个输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个功能:
func <-function(name){
paste(Your name is ...))
Sys.sleep(1.5)
paste(name)
}
这个函数显然不起作用,但想法是在每个输出之间等待1.5秒。
例如,调用func(Catherine )应该打印到控制台: [1]您的名字是...
$ c
$ b 然后等待1.5秒,然后打印:
[1]Catherine
解决方案您在 print
语句中输出所需的内容:
func <-function名称){
print(Your name is ...)
Sys.sleep(1.5)
print(name)
}
#Execute函数
func(Martin)
[1]您的名字是......
[1]Martin
I have this function:
func<-function(name){
paste("Your name is. . .")
Sys.sleep(1.5)
paste(name)
}
This function obviously won't work, but the idea is to wait 1.5 seconds between each output.
For example, calling func("Catherine") should print to console:
[1] "Your name is..."
Then wait 1.5 seconds, and print:
[1] "Catherine"
解决方案 Just wrap your desired output in a print
statement:
func<-function(name){
print("Your name is. . .")
Sys.sleep(1.5)
print(name)
}
#Execute Function
func("Martin")
[1] "Your name is. . ."
[1] "Martin"
这篇关于在R函数中使用Sys.sleep来延迟多个输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文