This function returns a function's output if the function runs, or allows the user to customise the error and warning messages if the function throws either.
1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | sum(c(1, 2, 3))
# an element of wrong type will cause sum to throw an error
## Not run:
sum(c(1, 2, "a"))
## End(Not run)
# toss returns function output if function runs
toss(sum(c(1, 2, 3)))
# toss returns NULL by default if function does not run
toss(sum(c(1, 2, "a")))
# toss allows you to customise the error message
toss(sum(c(1, 2, "a")), error_msg = "the cake is a lie")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.