Description Usage Arguments Details Value Examples

These functions wrap functions so that instead of generating side effects through printed output, messages, warnings, and errors, they return enhanced output. They are all adverbs because they modify the action of a verb (a function).

1 2 3 4 5 6 7 |

`.f` |
A function, formula, or vector (not necessarily atomic). If a If a For a single argument function, use `.` For a two argument function, use `.x` and`.y` For more arguments, use `..1` ,`..2` ,`..3` etc
This syntax allows you to create very compact anonymous functions. If |

`otherwise` |
Default value to use when an error occurs. |

`quiet` |
Hide errors ( |

If you would like to include a function created with `safely`

, `slowly`

, or
`insistently`

in a package, see faq-adverbs-export.

`safely`

: wrapped function instead returns a list with
components `result`

and `error`

. If an error occurred, `error`

is
an `error`

object and `result`

has a default value (`otherwise`

).
Else `error`

is `NULL`

.

`quietly`

: wrapped function instead returns a list with components
`result`

, `output`

, `messages`

and `warnings`

.

`possibly`

: wrapped function uses a default value (`otherwise`

)
whenever an error occurs.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | ```
safe_log <- safely(log)
safe_log(10)
safe_log("a")
list("a", 10, 100) %>%
map(safe_log) %>%
transpose()
# This is a bit easier to work with if you supply a default value
# of the same type and use the simplify argument to transpose():
safe_log <- safely(log, otherwise = NA_real_)
list("a", 10, 100) %>%
map(safe_log) %>%
transpose() %>%
simplify_all()
# To replace errors with a default value, use possibly().
list("a", 10, 100) %>%
map_dbl(possibly(log, NA_real_))
# For interactive usage, auto_browse() is useful because it automatically
# starts a browser() in the right place.
f <- function(x) {
y <- 20
if (x > 5) {
stop("!")
} else {
x
}
}
if (interactive()) {
map(1:6, auto_browse(f))
}
# It doesn't make sense to use auto_browse with primitive functions,
# because they are implemented in C so there's no useful environment
# for you to interact with.
``` |

```
$result
[1] 2.302585
$error
NULL
$result
NULL
$error
<simpleError in .f(...): non-numeric argument to mathematical function>
$result
$result[[1]]
NULL
$result[[2]]
[1] 2.302585
$result[[3]]
[1] 4.60517
$error
$error[[1]]
<simpleError in .f(...): non-numeric argument to mathematical function>
$error[[2]]
NULL
$error[[3]]
NULL
$result
[1] NA 2.302585 4.605170
$error
$error[[1]]
<simpleError in .f(...): non-numeric argument to mathematical function>
$error[[2]]
NULL
$error[[3]]
NULL
[1] NA 2.302585 4.605170
```

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.