I'm trying to use purrr::possibly()
to skip over errors in my code, but for some reason, when I use possibly()
here, it returns the output as if everything is an error.
Here's an example:
library(purrr)
add_things <- function(number) {
new_number <- number + 1
return(new_number)
}
possibly_add_things <- possibly(add_things, otherwise = NA)
# Works
map(c(1, 2, 3), possibly_add_things)
#> [[1]]
#> [1] 2
#>
#> [[2]]
#> [1] 3
#>
#> [[3]]
#> [1] 4
# Shouldn't be all NAs -- only the 2nd one
map(c(1, "hi", 3), possibly_add_things)
#> [[1]]
#> [1] NA
#>
#> [[2]]
#> [1] NA
#>
#> [[3]]
#> [1] NA
Created on 2021-05-11 by the reprex package (v1.0.0)
Any advice would be greatly appreciated.