Debian Codegraph @

man/later.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/later.R
3 \name{later}
4 \alias{later}
5 \title{Executes a function later}
6 \usage{
7 later(func, delay = 0, loop = current_loop())
8 }
9 \arguments{
10 \item{func}{A function or formula (see \code{\link[rlang:as_function]{rlang::as_function()}}).}
11
12 \item{delay}{Number of seconds in the future to delay execution. There is no
13 guarantee that the function will be executed at the desired time, but it
14 should not execute earlier.}
15
16 \item{loop}{A handle to an event loop. Defaults to the currently-active loop.}
17 }
18 \value{
19 A function, which, if invoked, will cancel the callback. The
20 function will return \code{TRUE} if the callback was successfully
21 cancelled and \code{FALSE} if not (this occurs if the callback has
22 executed or has been cancelled already).
23 }
24 \description{
25 Schedule an R function or formula to run after a specified period of time.
26 Similar to JavaScript's \code{setTimeout} function. Like JavaScript, R is
27 single-threaded so there's no guarantee that the operation will run exactly
28 at the requested time, only that at least that much time will elapse.
29 }
30 \details{
31 The mechanism used by this package is inspired by Simon Urbanek's
32 \href{https://github.com/s-u/background}{background} package and similar code in
33 Rhttpd.
34 }
35 \note{
36 To avoid bugs due to reentrancy, by default, scheduled operations only run
37 when there is no other R code present on the execution stack; i.e., when R is
38 sitting at the top-level prompt. You can force past-due operations to run at
39 a time of your choosing by calling \code{\link[=run_now]{run_now()}}.
40
41 Error handling is not particularly well-defined and may change in the future.
42 options(error=browser) should work and errors in \code{func} should generally not
43 crash the R process, but not much else can be said about it at this point.
44 If you must have specific behavior occur in the face of errors, put error
45 handling logic inside of \code{func}.
46 }
47 \examples{
48 # Example of formula style
49 later(~cat("Hello from the past\n"), 3)
50
51 # Example of function style
52 later(function() {
53 print(summary(cars))
54 }, 2)
55
56 }