# simple example, runs after a second
after(1000, function() cat("Here I am!\n"))
# supplying arguments
x <- "print me!"
after(1000, function(x) print(x), args = list(x))
# we can remove x now, it is already stored in the timer
rm(x)
# calling functions in packages
# Instead of after(1000, utils::alarm) use
after(1000, function() utils::alarm())
# in case utils::alarm() uses other functions from the
# utils package.
# repeat a task
x <- after(1000, function() print("still here"), redo = 5)
Sys.sleep(3)
# list tasks
after$list()
# cancel a task
after$cancel(x)
Run the code above in your browser using DataCamp Workspace