Using possibly()

1. possibly()

Let's see another way to write safe to use functions.

2. About possibly()

Let's now have a look at the possibly() function. This function is another adverb, like safely(), the difference being that it returns either the result of the function or the value you have specified in the otherwise argument. Remember that safely() always return a list of two elements: $result and $error. We use possibly() when we are not interested in why the function failed. As you have seen in the exercises, when you use safely, you have access to the content of the error. But maybe this error doesn't matter to you; you just want to know which function call succeeded.

3. Using possibly()

possibly() can return several values: a logical (TRUE or FALSE), a character vector, a missing value, a number, or even a NULL, as we will see later. Remember though that this element should be a value, not a function; you can't make possibly() execute a function when there is an error.

4. Let's practice!

Let's try to use possibly() on some examples.