# NOT RUN {
# The `try` command in following examples are here to make sure the
# R CMD check will pass on package check. In a real case, you do not
# need it.
# default
try(timeout({Sys.sleep(0.1)}, time_out = 0.01))
# timeout is evaluating expressions the same level as you call it
timeout({abc <- 123})
# so you should get `abc` even outside the function call
abc
# custom timeout callback
timeout({Sys.sleep(0.1)}, time_out = 0.01, on_timeout = {print("It takes too long")})
# final call back
try(timeout({Sys.sleep(0.1)}, time_out = 0.01, on_final = {print("some final words")})) # on error
timeout({123}, on_final = {print("runs even success")}) # on success
# assign to value
my_val <- timeout({10 + 1})
my_val
# }
Run the code above in your browser using DataLab