Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

timeout

Return a new number after a given number of seconds


Description

This function will return a number corresponding to the system time and remain stable until a given number of seconds have elapsed, after which it will update to the current time. This makes it useful as a way to timeout and invalidate a memoised cache after a certain period of time.

Usage

timeout(seconds, current = as.numeric(Sys.time()))

Arguments

seconds

Number of seconds after which to timeout.

current

The current time as a numeric.

Value

A numeric that will remain constant until the seconds have elapsed.

See Also

Examples

a <- function(n) { runif(n) }
memA <- memoise(a, ~timeout(10))
memA(2)

memoise

Memoisation of Functions

v2.0.0
MIT + file LICENSE
Authors
Hadley Wickham [aut], Jim Hester [aut, cre], Winston Chang [aut], Kirill Müller [aut], Daniel Cook [aut], Mark Edmondson [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.