Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/moodymudskipper/inops
Infix Operators for Detection, Subsetting and Replacement
https://github.com/moodymudskipper/inops
r r-language r-package r-programming r-stats
Last synced: 2 months ago
JSON representation
Infix Operators for Detection, Subsetting and Replacement
- Host: GitHub
- URL: https://github.com/moodymudskipper/inops
- Owner: moodymudskipper
- License: gpl-3.0
- Created: 2019-07-20T18:25:01.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-11-19T13:56:55.000Z (about 5 years ago)
- Last Synced: 2024-10-28T17:32:42.196Z (3 months ago)
- Topics: r, r-language, r-package, r-programming, r-stats
- Language: R
- Homepage:
- Size: 187 KB
- Stars: 40
- Watchers: 4
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE.md
Awesome Lists containing this project
- jimsghstars - moodymudskipper/inops - Infix Operators for Detection, Subsetting and Replacement (R)
README
---
output: github_document
---```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)options(width=110)
```# 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**.![inops_operator_table](http://karolis.koncevicius.lt/data/inops/inops_operator_table.png)
For more examples please see the vignette.\
For a complete list of available operators consult the tables below.## Syntax ##
All operators have the same form composed of two distinct parts: `%%`.
* `[operation]` specifies the performed functionality and can be one of `in`, `out`, `[in`, `[out`.
* `[type]` specifies the type of operation and can be one of `{}`, `[]`, `()`, `[)`, `(]`, `~`, `~p`, `~f`, `#`.### 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 |
|-------------|--------------------------------------------------------------------------|-------------------------------|
| `%[==%` | select elements equal to the provided value | `x %[==% element` |
| `%[!=%` | select elements not equal to the provided value | `x %[!=% element` |
| `%[>%` | select elements greater than the provided value | `x %[>% number` |
| `%[<%` | select elements lower than the provided value | `x %[<% number` |
| `%[>=%` | select elements greater or equal to the provided value | `x %[>=% number` |
| `%[<=%` | select elements lower or equal to the provided value | `x %[<=% number` |
| `%[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 ##
1. **Overloading**
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.2. **Behaviour**
Detection operators should be seen as an extension of the standard infix operators implemented in R (i.e. `==`, `>`, etc).
For this reason the implemented operators differ from standard `%in%` and behave more like `==` on `data.frames` and objects with `NA` values.Subsetting and replacement operators are wrappers around detection operators.\
Subsetting: `x[ x %in{}% set]`.\
Replacement: `replace(x, x %in{}% set, value)`.## See Also ##
Other similar packages you might be interested in.
1. [intrval](https://github.com/psolymos/intrval)
2. [operators](https://github.com/romainfrancois/operators)
3. [infix](https://github.com/ebeneditos/infix)
4. [invctr](https://github.com/FredHasselman/invctr)
5. [grapes](https://github.com/wlandau/grapes)