tests/testthat/test-adverb-safely.R

test_that("safely has NULL error when successful", {
  out <- safely(log10)(10)
  expect_equal(out, list(result = 1, error = NULL))
})

test_that("safely has NULL result on failure", {
  out <- safely(log10)("a")
  expect_equal(out$result, NULL)
  expect_equal(out$error$message,
    "non-numeric argument to mathematical function")
})

Try the purrr package in your browser

Any scripts or data that you put into this service are public.

purrr documentation built on April 3, 2025, 6:13 p.m.