Skip to contents

[Stable]

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.

Usage

expect(x, msg, ...)

Arguments

x

The object to unwrap.

msg

The message to be included if a condition is thrown.

...

Additional optional arguments that may be used by specific methods.

Value

The value wrapped by x if a condition was not thrown as result of a Failure or Nothing value.

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")
} # }