Provides adds postfix and infix logic operators for if, then, unless, and otherwise.
The goal of postlogic is to allow natural flowing logic statements.
You can install the released version of postlogic from CRAN with:
The if/otherwise instruction allows for simple logic to follow a statement to make it conditional. The
%if% can be used alone to make an action conditional.
verbose <- TRUEmessage("Hello there") %if% verbose
When combined with the
%otherwise% statement it allows for an alternate.
mood <- "calm"message("How dare you!") %if% (mood == 'angry') %otherwise%message("Everything is fine.")#> Everything is fine.mood <- 'angry'message("How dare you!") %if% (mood == 'angry') %otherwise%message("Everything is fine.")#> How dare you!
%unless% operator is essentially the negation of
%if%. So when a statement is postfixed by an
%unless% statement it will happen unless the proposition returns
TRUE. The alternating operator for
mood <- 'calm'message("Everything is fine.") %unless% (mood == 'angry') %then%message("How dare you!")#> Everything is fine.
This example is the same effect as the statements in the previous example.