| Title: | Basic Infix Binary Operators |
|---|---|
| Description: | Contains a number of infix binary operators that may be useful in day to day practices. |
| Authors: | Ernest Benedito [aut, cre] |
| Maintainer: | Ernest Benedito <[email protected]> |
| License: | GPL-3 |
| Version: | 0.1.0 |
| Built: | 2026-05-12 05:57:27 UTC |
| Source: | https://github.com/ebeneditos/infix |
Use this method to handle errors. The function evaluates an expression, and if it raises an error then evaluates a second expression.
tryExcept(expr, except = { }, error = function(e) { }) expr %except% excepttryExcept(expr, except = { }, error = function(e) { }) expr %except% except
expr |
Expression to be evaluated. |
except |
Expression to be evaluated if |
error |
Handler function for an |
tryExcept is a wrapper around tryCatch,
but it allows you to evaluate an expression except when an error occurs to
the first expression argument expr. Note that, if expr raises
an error, the code evaluated before the error will be in use.
# No errors are raised tryExcept(stop()) # If 'expr' has no errors tryExcept({ foo <- "foo" }, except = { foo <- "foo bar" }) print(foo) # "foo" # If 'expr' has an error tryExcept({ foo <- "foo" stop() }, except = { foo <- "foo bar" }) print(foo) # "foo bar" # Running it with the infix operator {foo <- "foo"} %except% {foo <- "foo bar"} print(foo) # "foo" { foo <- "foo" stop() } %except% { foo <- "foo bar" } print(foo) # "foo bar"# No errors are raised tryExcept(stop()) # If 'expr' has no errors tryExcept({ foo <- "foo" }, except = { foo <- "foo bar" }) print(foo) # "foo" # If 'expr' has an error tryExcept({ foo <- "foo" stop() }, except = { foo <- "foo bar" }) print(foo) # "foo bar" # Running it with the infix operator {foo <- "foo"} %except% {foo <- "foo bar"} print(foo) # "foo" { foo <- "foo" stop() } %except% { foo <- "foo bar" } print(foo) # "foo bar"
Analogous to file.path(x, y).
x %//% yx %//% y
x, y
|
Character vectors. |
"home" %//% "dir" # returns "home/dir""home" %//% "dir" # returns "home/dir"
Creates a function which returns the corresponding logical
operation between what f1 and f2 return.
f1 %&% f2 f1 %|% f2 f1 %xor% f2f1 %&% f2 f1 %|% f2 f1 %xor% f2
f1, f2
|
Arbitrary predicate functions. |
To obtain the logical negation of what a function f returns,
use base function Negate.
is.null.na <- is.null %|% is.na all(is.null.na(NA), is.null.na(NULL)) # returns TRUEis.null.na <- is.null %|% is.na all(is.null.na(NA), is.null.na(NULL)) # returns TRUE
Contains a number of infix binary operators that may be useful in day to day practices.
exceptSimple Error Handling.
operatorsCommon Infix Operators.
funlogicFunction Logical Operators.
pipesPackage's 'magrittr' pipe-operators.
Maintainer: Ernest Benedito [email protected]
Useful links:
NULL
This infix function makes it easy to replace NULL's with
a default value. It's inspired by the way that Ruby's or operation
(`||`) works.
a %||% ba %||% b
a, b
|
If |
1 %||% 2 # returns 1 NULL %||% 2 # returns 21 %||% 2 # returns 1 NULL %||% 2 # returns 2
The logical negation of %in%.
x %!in% tablex %!in% table
x |
Vector or |
table |
Vector or |
4 %!in% 1:3 # returns TRUE4 %!in% 1:3 # returns TRUE
Common Infix Operators
paste0Concatenate Strings (see ?"%+%").
file.pathConstruct Path to File (see ?"%//%").
nomatchValue (non) Matching (see ?"%!in%").
nilDefault value for NULL (see ?"%||%").
Analogous to paste0(x, y).
x %+% yx %+% y
x, y
|
Objects to be converted to character vectors. |
"01" %+% "jan" %+% "1970" # returns "01jan1970""01" %+% "jan" %+% "1970" # returns "01jan1970"