%btwn% {infixit}R Documentation

Between Infix Operator

Description

Currently in R, if you want to test if a value is between two others, you have to set it up in a cumbersome manner: X > Y & X < Z. ⁠%btwn%⁠ simplifies the operation into a single call: X %btwn% c(Y, Z).

Usage

lhs %btwn% rhs

Arguments

lhs

The left-hand side, the value(s) to be compared.

rhs

The right-hand side, the comparative range. Must be a numeric vector of length 2 with the smaller value prior to the larger value. Identical values can be passed.

Details

By default, ⁠%btwn%⁠ evaluates inclusively. That is, if the right-hand side is c(1, 5) and the left-hand side is c(1,5), it will evaluate as ⁠TRUE TRUE⁠. If one wants to adjust this default behavior, they can adjust the "infix.btwn" option to be either inclusive for the lower-bound ("["), exclusive for the lower- bound ("("), inclusive for the upper-bound ("]"), or exclusive for the upper-bound (")"). To set an inclusive lower-bound but exclusive upper-bound, for example, you would do as follows: options(infixit.btwn = c("[", ")")). Additional options allow you to set which date formats are automatically parsed when comparing if one date is within another (infixit.btwn.datetimefmt), and whether ⁠%btwn%⁠ will ignore NA values in the comparison or return them as FALSE (infixit.btwn.ignore_na)

Value

A Boolean vector the same length as the left-hand side input.

Examples

{
  13 %btwn% c(12.5, 15) #returns TRUE
}


[Package infixit version 0.3.1 Index]