File: ani.pause.R

package info (click to toggle)
r-cran-animation 2.7%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,268 kB
  • sloc: javascript: 873; sh: 15; makefile: 2
file content (30 lines) | stat: -rw-r--r-- 898 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#' Pause for a while and flush the current graphical device
#'
#' If this function is called in an interactive graphics device, it will pause
#' for a time interval (by default specified in
#' \code{\link{ani.options}('interval')}) and flush the current device;
#' otherwise it will do nothing.
#' @param interval a time interval to pause (in seconds)
#' @return Invisible \code{NULL}.
#' @author Yihui Xie
#' @seealso \code{\link{dev.interactive}}, \code{\link{Sys.sleep}},
#'   \code{\link{dev.flush}}
#' @export
#' @examples ## pause for 2 seconds
#' oopt = ani.options(interval = 2)
#'
#' for (i in 1:5) {
#'   plot(runif(10), ylim = c(0, 1))
#'   ani.pause()
#' }
#'
#' ani.options(oopt)
#'
#' ## see demo('Xmas2', package = 'animation') for another example
#'
ani.pause = function(interval = ani.options('interval')) {
  if (dev.interactive()) {
    dev.flush()
    Sys.sleep(interval)
  }
}