stop_if: Simple side effect functions

Description Usage Arguments Details Author(s) Examples

View source: R/do_if.R

Description

\Sexpr[results=rd, stage=render]{lifecycle::badge("experimental")}

If the condition is TRUE, generate error/warning/message from the supplied message.

Usage

1
2
3
4
5
stop_if(condition, message = NULL, sys.parent.n = 0L)

warn_if(condition, message = NULL, sys.parent.n = 0L)

message_if(condition, message = NULL, sys.parent.n = 0L)

Arguments

condition

The condition to check. (Logical)

message

Message. (Character)

Note: If NULL, the condition will be used as message.

sys.parent.n

The number of generations to go back when calling message function.

Details

When condition is FALSE, they return NULL invisibly.

When condition is TRUE:

stop_if()

Throws error with the supplied message.

warn_if()

Throws warning with the supplied message.

message_if()

Generates message with the supplied message.

Author(s)

Ludvig Renbo Olsen, r-pkgs@ludvigolsen.dk

Examples

1
2
3
4
5
6
7
# Attach packages
library(rtilities2)

a <- 0
stop_if(a == 0, "'a' cannot be 0.")
warn_if(a == 0, "'a' was 0.")
message_if(a == 0, "'a' was so kind to be 0.")

LudvigOlsen/rtilities2 documentation built on Jan. 19, 2020, 4:57 a.m.