Learn R Programming

conditions (version 0.1)

as_message: Convert Conditions

Description

These functions are intended to change the class of conditions. In combination with tryCatch, unspecified conditions can easily be casted to a more specific type. See condition for a short explanation about the predefined condition classes.

Usage

as_message(class, message = NULL)
as_warning(class, message = NULL)
as_error(class, message = NULL)
as_assertion_message(message = NULL)
as_deprecated_message(message = NULL)
as_dimension_message(message = NULL)
as_future_message(message = NULL)
as_index_message(message = NULL)
as_io_message(message = NULL)
as_length_message(message = NULL)
as_library_message(message = NULL)
as_lookup_message(message = NULL)
as_missing_message(message = NULL)
as_name_message(message = NULL)
as_runtime_message(message = NULL)
as_type_message(message = NULL)
as_value_message(message = NULL)
as_assertion_warning(message = NULL)
as_deprecated_warning(message = NULL)
as_dimension_warning(message = NULL)
as_future_warning(message = NULL)
as_index_warning(message = NULL)
as_io_warning(message = NULL)
as_length_warning(message = NULL)
as_library_warning(message = NULL)
as_lookup_warning(message = NULL)
as_missing_warning(message = NULL)
as_name_warning(message = NULL)
as_runtime_warning(message = NULL)
as_type_warning(message = NULL)
as_value_warning(message = NULL)
as_assertion_error(message = NULL)
as_deprecated_error(message = NULL)
as_dimension_error(message = NULL)
as_future_error(message = NULL)
as_index_error(message = NULL)
as_io_error(message = NULL)
as_length_error(message = NULL)
as_library_error(message = NULL)
as_lookup_error(message = NULL)
as_missing_error(message = NULL)
as_name_error(message = NULL)
as_runtime_error(message = NULL)
as_type_error(message = NULL)
as_value_error(message = NULL)

Arguments

class
[character] New classes for the condition.
message
[character] If provided, overwrites the original condition message.

Value

[function]. Returns a function which takes a condition as first argument, creates a new condition of the respective type and signals the created condition with message, warning or stop, respectively.

Examples

Run this code
# Turn the warning of sqrt() into a value message
message(tryCatch(sqrt(-1), warning = as_value_message()))

## Not run: 
# # Turn the warning of sqrt() into a value error
# tryCatch(sqrt(-1), warning = as_value_error())
# 
# # Or, alternatively with a custom message:
# tryCatch(sqrt(-1), warning = as_value_error("sqrt of negative value"))
# ## End(Not run)

Run the code above in your browser using DataLab