😎 Give your xaringan slides some style
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

19 lines
453B

  1. with_clean_session <- function(.f, args = list()) {
  2. empty_wd <- tempfile()
  3. dir.create(empty_wd)
  4. owd <- setwd(empty_wd)
  5. on.exit({setwd(owd); unlink(empty_wd, TRUE)})
  6. args$.f <- .f
  7. res <- callr::r_safe(function(.f, ...) {
  8. tryCatch(
  9. list(result = .f(...), error = NULL),
  10. error = function(e) list(result = NULL, error = e$message)
  11. )
  12. }, args)
  13. if (!is.null(res$error)) {
  14. stop(res$error)
  15. } else {
  16. res$result
  17. }
  18. }