These functions can be used to supply an alert to the user that the evaluation of an expression succeeded or resulted in an error.
Usage
ft_beep_success_error(expr, success = 4, error = 2)
ft_ntfy_success_error(
expr,
success = "It Worked!",
error = "Better Check on Me."
)
ft_notify_success_error(
expr,
success = "All done!",
error = "Shit!",
image = NULL
)
Details
Each of these functions takes an expression as the first argument, so it is possible to pipe into them, or just wrap the expression to run. They check if the evaluated expression returns an error or not, so they can give the correct feedback to the user.
Examples
if (require(beepr)) {
# usual syntax, works
ft_beep_success_error(Sys.sleep(2))
# have an error (can't add a letter to a number)
ft_beep_success_error(2 + "x")
# pipe syntax
Sys.sleep(2) |> ft_beep_success_error()
}
#> Loading required package: beepr
#> Error in 2 + "x" : non-numeric argument to binary operator
#> NULL