Closed melonki closed 2 years ago
You can just use safely()
to wrap the function that you'd send to the worker, like how you'd use it with map()
. i.e.
library(furrr)
#> Loading required package: future
library(purrr)
safe_log <- safely(log)
safe_log(10)
#> $result
#> [1] 2.302585
#>
#> $error
#> NULL
safe_log("a")
#> $result
#> NULL
#>
#> $error
#> <simpleError in .Primitive("log")(x, base): non-numeric argument to mathematical function>
list("a", 10, 100) %>%
map(safe_log)
#> [[1]]
#> [[1]]$result
#> NULL
#>
#> [[1]]$error
#> <simpleError in .Primitive("log")(x, base): non-numeric argument to mathematical function>
#>
#>
#> [[2]]
#> [[2]]$result
#> [1] 2.302585
#>
#> [[2]]$error
#> NULL
#>
#>
#> [[3]]
#> [[3]]$result
#> [1] 4.60517
#>
#> [[3]]$error
#> NULL
plan(multisession, workers = 2)
list("a", 10, 100) %>%
future_map(safe_log)
#> [[1]]
#> [[1]]$result
#> NULL
#>
#> [[1]]$error
#> <simpleError in .Primitive("log")(x, base): non-numeric argument to mathematical function>
#>
#>
#> [[2]]
#> [[2]]$result
#> [1] 2.302585
#>
#> [[2]]$error
#> NULL
#>
#>
#> [[3]]
#> [[3]]$result
#> [1] 4.60517
#>
#> [[3]]$error
#> NULL
Created on 2022-05-06 by the reprex package (v2.0.1)
You can just use
safely()
to wrap the function that you'd send to the worker, like how you'd use it withmap()
. i.e.library(furrr) #> Loading required package: future library(purrr) safe_log <- safely(log) safe_log(10) #> $result #> [1] 2.302585 #> #> $error #> NULL safe_log("a") #> $result #> NULL #> #> $error #> <simpleError in .Primitive("log")(x, base): non-numeric argument to mathematical function> list("a", 10, 100) %>% map(safe_log) #> [[1]] #> [[1]]$result #> NULL #> #> [[1]]$error #> <simpleError in .Primitive("log")(x, base): non-numeric argument to mathematical function> #> #> #> [[2]] #> [[2]]$result #> [1] 2.302585 #> #> [[2]]$error #> NULL #> #> #> [[3]] #> [[3]]$result #> [1] 4.60517 #> #> [[3]]$error #> NULL plan(multisession, workers = 2) list("a", 10, 100) %>% future_map(safe_log) #> [[1]] #> [[1]]$result #> NULL #> #> [[1]]$error #> <simpleError in .Primitive("log")(x, base): non-numeric argument to mathematical function> #> #> #> [[2]] #> [[2]]$result #> [1] 2.302585 #> #> [[2]]$error #> NULL #> #> #> [[3]] #> [[3]]$result #> [1] 4.60517 #> #> [[3]]$error #> NULL
Created on 2022-05-06 by the reprex package (v2.0.1)
Thank you so much for your quick response!
Dear Contributors and Members,
Thank you for your great efforts in developing furrr! It has accelerated my work a lot. However, I found it's hard to locate errors and debug. Are there any functions working like
possibly
orsafely
frompurrr
? I would appreciate it if you would provide any suggestions!Best, Melonki