7.7 Possibly and quietly succeeds

Possibly always succeeds by giving it a default value. Safely defaults to NULL, possibly requres the otherwise parameter

x <- list(1, 10, "a")
x %>% map_dbl(possibly(log, NA_real_))
## [1] 0.000000 2.302585       NA

quietly captures output, messages, and warnings, instead of errors

x <- list(1, -1)
x %>% map(quietly(log)) %>% str()
## List of 2
##  $ :List of 4
##   ..$ result  : num 0
##   ..$ output  : chr ""
##   ..$ warnings: chr(0) 
##   ..$ messages: chr(0) 
##  $ :List of 4
##   ..$ result  : num NaN
##   ..$ output  : chr ""
##   ..$ warnings: chr "NaNs produced"
##   ..$ messages: chr(0)
x %>% map(quietly(log)) %>% purrr::transpose() %>% str()
## List of 4
##  $ result  :List of 2
##   ..$ : num 0
##   ..$ : num NaN
##  $ output  :List of 2
##   ..$ : chr ""
##   ..$ : chr ""
##  $ warnings:List of 2
##   ..$ : chr(0) 
##   ..$ : chr "NaNs produced"
##  $ messages:List of 2
##   ..$ : chr(0) 
##   ..$ : chr(0)