使用计时器运行连续的“demo( )”以了解事件之间的变化

发布于 2024-12-23 02:41:09 字数 656 浏览 4 评论 0原文

假设我正在运行演示(图形),并且我想控制连续绘图的显示速度。通常,当我运行 demo(graphics) 时,我可以通过按 Enter 键来控制何时显示下一个绘图(这样可以触发 demo() 中的下一个函数)。但我不想按 Enter 键 - 我希望它自行运行,并在绘图显示之间进行时间控制的更改(例如绘图每 6 秒更改一次,3 秒后更改一次,等等)。下面是一个残酷代码,它在 2 秒后在两个 demo() 函数之间进行更改。我还使用 echo=FALSE快速模式中运行demo()。但我想在一个 demo() 中做到这一点(如果可能的话,也可以在 example() 中实现)。

  library(tcltk2)
  test1 <- function() demo(graphics,echo=F)
  test2 <- function() demo(lm.glm, package="stats",echo=F)
  tclTaskSchedule(2000, test1())
  Sys.sleep(2)
  tclTaskSchedule(2000, test2())
  Sys.sleep(2)

Lets say I am running demo(graphics) and I want to control the speed with which consecutive plots are displayed. Normally when I run demo(graphics) I can control when the next plot will display by pressing enter (and this way triggering next function in demo()). But I don't want to press enter - I want it to run on its own, with the time-controlled changes between plot displays (for example the plot would change every 6 seconds, next after 3 seconds, etc.). Below is a brutal code that changes between two demo() functions after 2 seconds. I also run demo() in quick-mode using echo=FALSE. But I would like to do that WITHIN a single demo() (and for the example() too if possible).

  library(tcltk2)
  test1 <- function() demo(graphics,echo=F)
  test2 <- function() demo(lm.glm, package="stats",echo=F)
  tclTaskSchedule(2000, test1())
  Sys.sleep(2)
  tclTaskSchedule(2000, test2())
  Sys.sleep(2)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧梦荧光笔 2024-12-30 02:41:09

只需设置 before.plot.new 钩子即可添加延迟:

setHook("before.plot.new", function(...) Sys.sleep(1))
demo(graphics, ask=F)

Simply set before.plot.new hook to add delays:

setHook("before.plot.new", function(...) Sys.sleep(1))
demo(graphics, ask=F)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文