# NOT RUN {
tf <- tempdir()
testfun <- function(a = 1, time = 3){
Sys.sleep(time)
return(a + 0.1 * abs(rnorm(1)))
}
# First time running; the function takes some time, memento needs the
# output to be generated, and will remember for later.
set.seed(43)
memento(testfun, args = list(a = 7), name = "T1", dir = tf)
set.seed(43)
testfun(7, time = 0)
# Second time running: memento directly outputs the remembered results.
# In this case, the seed is ignored, so the result is different from what
# would be obtained with a different seed
set.seed(45)
memento(testfun, args = list(a = 7), name = "T1", dir = tf)
set.seed(45)
testfun(7, time = 0)
# First time running while taking into account the random seed;
# the function takes some time to generate the result
set.seed(42)
memento(testfun, args = list(a = 7), name = "T1", dir = tf, check.seed = TRUE)
# Second time running with an identical random seed;
# memento directly outputs the results
set.seed(42)
memento(testfun, args = list(a = 7), name = "T1", dir = tf, check.seed = TRUE)
# The seed is changed: the result is computed anew
set.seed(47)
memento(testfun, args = list(a = 7), name = "T1", dir = tf, check.seed = TRUE)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab