extraoperators

CRAN_status R-CMD-check codecov lifecycle

An R package with operators to help speed up everyday tasks.

Installation

To get the latest development version, use:

#install.packages("devtools")
devtools::install_github("JWiley/extraoperators")

Otherwise to get from CRAN use:

install.packages("extraoperators")

Overview

The table below summarizes what this package provides. Fundamentally it provides or expands on several logical operators, which can be accessed on their own to return a logical vector, but also prefixed by ? (which) to return the indices that are TRUE or prefixed by s (subset) to return only those values that are TRUE or prefixed by a (all) to return a single logical value, are ALL true? They can also be prefixed by any to return a single logical value, is ANY true? An entire all logical comparison can be prefixed by ! to generate a NONE evaluation.

Operator What it does Which? Subset All Any
== Are values / vectors equal %?==% %s==% %a==% %any==%
!= Are values / vector NOT equal %?!=% %s!=% %a!=% %any!=%
%l% Less than %?l% %sl% %al% %anyl%
%le% Less than or equal %?le% %sle% %ale% %anyle%
%g% Greater than %?g% %sg% %ag% %anyg%
%ge% Greater than or equal %?ge% %sge% %age% %anyge%
%gl% Greater than AND less than %?gl% %sgl% %agl% %anygl%
%gel% Greater than or equal AND less than %?gel% %sgel% %agel% %anygel%
%gle% Greater than AND less than or equal %?gle% %sgle% %agle% %anygle%
%gele% Greater than or equal AND less than or equal %?gele% %sgele% %agele% %anygele%
%in% In %?in% %sin% %ain% %anyin%
%!in% OR %nin% Not in %?!in% OR %?nin% %s!in% OR %snin% %a!in% OR %anin% %any!in% OR %anynin%
%c% Chain operations on the RHS together %?c% %sc% %ac% %anyc%
%e% Set operator, to use set notation %?e% %se% %ae% %anye%
%grepl% does text match a regular expression %?grepl% %sgrepl% %agrepl% %anygrepl%
%!grepl% does text NOT match a regular expression %?!grepl% %s!grepl% %a!grepl% %any!grepl%
%flipIn% In, ignoring order around a colon %anyflipIn%
%===% Are objects strictly identical
%!==% Are objects not strictly identical

Using these operators, you can accomplish many different tasks by just remembering the additional prefixes: ? for which(), a for all(), any for any(), and s for subset(). While simple, this can save quite a few keystrokes and make various logical comparisons less convoluted.