The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.

inops vignette

inops

Package implementing additional infix operators for R.

Implemented operators work with 4 different value types: sets, intervals, regular expressions, and counts.
And provide 3 distinct functionalities: detection, subsetting, and replacement.

Install using the remotes package:

remotes::install_github("moodymudskipper/inops")

Syntax

All operators have the same form composed of two distinct parts: %<operation><type>%.

Value Types

  1. sets
 %in{}%
%out{}%

Work with the same values as %in% does but provide a more consistent behaviour for data.frames and NA values.

  1. ranges
 %in()%   %in[]%   %in[)%   %in(]%
%out()%  %out[]%  %out[)%  %out(]%
  1. patterns
 %in~%   %in~f%   %in~p%
%out~%  %out~f%  %out~p%
  1. counts
 %in#%
%out#%

Operations

  1. detection

Same form as examples shown above.

  1. subsetting

Used for obtaining actual values.
Starts with [.

  1. replacement

Used for replacing the matched elements with new values.
Called with assignment <- at the end.

Behaviour

The operators implemented here try to be consistent with the default comparison operators like == and <.
Therefore in some scenarios their behaviour differs from %in%.
For instance:

  1. %in{}% can be used on on data frames.
  1. missing values are not considered as not matching.

Additional Examples

Simple examples for illustration.


Selecting flight records from the flights dataset that:

  1. Departed and Landed between noon and 5 p.m.
  2. Were not traveling to “LEX”, “PSP”, nor “HDN”
  3. Travelled distance was either very short (below 100) or very long (above 3000)
  4. Had a tail number starting with “N1” or “N3”

Cleaning up planes dataset in order to:

  1. Standardize names of “AIRBUS”, “CANADAIR” and “MCDONNELL” manufacturers.
  2. Obtain plane counts for each of the 3 manufacturers mentioned above.

Combine engine models that in the dataset occur less than 6 times under the “Other” group.


Full List

Below is a full list of all the implemented operators along with their usage examples.

Detection Operators

Form Description Call
%in{}% which elements are inside a set x %in{}% set
%in[]% which elements are inside a closed interval x %in[]% interval
%in()% which elements are inside an open interval x %in()% interval
%in[)% which elements are inside an interval open on the right x %in[)% interval
%in(]% which elements are inside an interval open on the left x %in(]% interval
%in~% which elements match a regular expression x %in~% pattern
%in~p% which elements match a regular perl expression x %in~p% pattern
%in~f% which elements match a regular fixed expression x %in~f% pattern
%in#% which elements occur a specified number of times x %in#% count
%out% which elements are outside a set (same as ! x %in% y) x %out% set
%out{}% which elements are outside a set x %out{}% set
%out[]% which elements are outside a closed interval x %out[]% interval
%out()% which elements are outside an open interval x %out()% interval
%out[)% which elements are outside an interval open on the right x %out[)% interval
%out(]% which elements are outside an interval open on the left x %out(]% interval
%out~% which elements do not match a regular expression x %out~% pattern
%out~p% which elements do not match a regular perl expression x %out~p% pattern
%out~f% which elements do not match a regular fixed expression x %out~f% pattern
%out#% which elements occur other than a specified number of times x %out#% count

Subsetting Operators

Form Description Call
%[in% select elements inside a set x %[in% set
%[in{}% select elements inside a set x %[in{}% set
%[in[]% select elements inside a closed interval x %[in[]% interval
%[in()% select elements inside an open interval x %[in()% interval
%[in[)% select elements inside an interval open on the right x %[in[)% interval
%[in(]% select elements inside an interval open on the left x %[in(]% interval
%[in~% select elements matching a regular expression x %[in~% pattern
%[in~p% select elements matching a regular perl expression x %[in~p% pattern
%[in~f% select elements matching a regular fixed expression x %[in~f% pattern
%[in#% select elements that occur a specified number of times x %[in#% count
%[out% select elements outside a set x %[out% set
%[out{}% select elements outside a set x %[out{}% set
%[out[]% select elements outside a closed interval x %[out[]% interval
%[out()% select elements outside an open interval x %[out()% interval
%[out[)% select elements outside an interval open on the right x %[out[)% interval
%[out(]% select elements outside an interval open on the left x %[out(]% interval
%[out~% select elements not matching a regular expression x %[out~% pattern
%[out~p% select elements not matching a regular perl expression x %[out~p% pattern
%[out~f% select elements not matching a regular fixed expression x %[out~f% pattern
%[out#% select elements that occur other than specified number of times x %[out% count

Replacement Operators

Form Description Call
==<- change elements equal to the provided value x == element <- value
!=<- change elements not equal to the provided value x != element <- value
><- change elements greater than the provided value x > number <- value
<<- change elements lower than the provided value x < number <- value
>=<- change elements greater or equal to the provided value x >= number <- value
<=<- change elements lower or equal to the provided value x <= number <- value
%in%<- change elements inside a set x %in% set <- value
%in{}%<- change elements inside a set x %in{}% set <- value
%in[]%<- change elements inside a closed interval x %in[]% interval <- value
%in()%<- change elements inside an open interval x %in()% interval <- value
%in[)%<- change elements inside an interval open on the right x %in[)% interval <- value
%in(]%<- change elements inside an interval open on the left x %in(]% interval <- value
%in~%<- change elements matching a regular expression x %in~% pattern <- value
%in~p%<- change elements matching a regular perl expression x %in~p% pattern <- value
%in~f%<- change elements matching a regular fixed expression x %in~f% pattern <- value
%in#%<- change elements that occur specified number of times x %in#% count <- value
%out%<- change elements outside a set x %out% set <- value
%out{}%<- change elements outside a set x %out{}% set <- value
%out[]%<- change elements outside a closed interval x %out[]% interval <- value
%out()%<- change elements outside an open interval x %out()% interval <- value
%out[)%<- change elements outside an interval open on the right x %out[)% interval <- value
%out(]%<- change elements outside an interval open on the left x %out(]% interval <- value
%out~%<- change elements not matching a regular expression x %out~% pattern <- value
%out~p%<- change elements not matching a regular perl expression x %out~p% pattern <- value
%out~f%<- change elements not matching a regular fixed expression x %out~f% pattern <- value
%out#%<- change elements that occur other than specified number of times x %out#% count <- value

Notes

To give an assignment counterpart to < we had to overload the <<- operator, which explains the message when attaching the package. This doesn’t affect the behavior of the <<- assignments.

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.
Health stats visible at Monitor.