Get the wrapped value from a Result
or Option
object
expect.Rd
If the provided object is a Failure
(in the case of a Result
input) or
Nothing
(in the case of an Option
input), then the function will 'panic'
and throw an error of class expect_panic
, with the message body set to
msg
.
See also
expect_fail()
to unwrap details of a Failure
instead,
unwrap()
for a similar function that doesn't require msg
.
Examples
Success(10) |> expect("This value should have been successfully computed")
#> [1] 10
Some("optional string") |> expect("Actually we require the string")
#> [1] "optional string"
if (FALSE) { # \dontrun{
Failure("Oh no I failed because of bad parameters") |>
expect("This value should have been successfully computed")
Nothing() |> expect("Actually we require the string")
} # }