Wrapper: Wrap a value and optional messages

View source: R/Wrapper.R

WrapperR Documentation

Wrap a value and optional messages

Description

The wrap function wraps a value inside a Wrapper container, possibly incorporating wrapped messages, too.

Usage

Wrapper(
  value,
  errors = list(),
  warnings = list(),
  info = list(),
  include = list(),
  ...
)

is.Wrapper(x)

Arguments

errors

List of error messages (list, optional)

warnings

List of warning messages (list, optional)

info

List of informational messages (list, optional)

include

A list of already-wrapped objects, who's errors, warnings, and infos should be included in this wrapper

x

A value to be wrapped

quiet

If TRUE, print the enclosed messages, if any, before extracting the enclosed value (logical)

Details

The unwrap function extracts the value from the container. Unless quiet = TRUE, it will print the wrapped, associated messages, if any, before returning that extracted value (so the message are not ignored).

As a convenience to the caller, the errors, warnings, and info may be supplied as character vectors (or even NULL), but they will be coerced to lists and stored as lists.

Value

Wrapper and wrap eturn a list with class Wrapper. unwrap returns the value wrapped inside the Wrapper container.

Examples

w <- wrap(pi, error = "Help me!", warnings = "Just chillin'")

# Extract the wrapped value
unwrap(w)

# Extract the wrapped value and print the wrapped messages
unwrap(w, quiet = FALSE)

# Piggy back the error messages
wrap(pi, error = "Pi error", include = list( wrap("foo", error = "Foo error") ))


pteetor/tutils documentation built on March 29, 2025, 6:38 p.m.