
<!-- README.md is generated from README.Rmd. Please edit THAT file, then run devtools::build_readme(). -->

# roperators

<!-- badges: start -->

[![CRAN
version](https://img.shields.io/cran/v/roperators?style=flat-square)](https://cran.r-project.org/package=roperators)
[![metacran
downloads](https://cranlogs.r-pkg.org/badges/last-month/roperators)](https://cran.r-project.org/package=roperators)
[![License:
MIT](https://img.shields.io/cran/l/roperators?style=flat-square)](https://cran.r-project.org/package=roperators)
[![R-CMD-check](https://github.com/BenWiseman/roperators/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/BenWiseman/roperators/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->

> Small, friendly operators and helpers that let your R code read the
> way you already think it.

<div id="rop-hero">

<h3>

Which would you rather write?
</h3>

<table>

<thead>

<tr>

<th>

base R
</th>

<th>

roperators  ← cleaner
</th>

</tr>

</thead>

<tbody>

<tr>

<td>

<code>paste0(“Hi”, name, “, you have”, n)</code>
</td>

<td>

<code>f(“Hi {name}, you have {n}”)</code>
</td>

</tr>

<tr>

<td>

<code>c(1, NA, 3) == c(1, NA, 4)</code>
</td>

<td>

<code>c(1, NA, 3) %==% c(1, NA, 4)</code>
</td>

</tr>

<tr>

<td>

<code>isTRUE(all.equal(0.1 + 0.1 + 0.1, 0.3))</code>
</td>

<td>

<code>(0.1 + 0.1 + 0.1) %~=% 0.3</code>
</td>

</tr>

<tr>

<td>

<code>x\[is.na(x)\] \<- 0</code>
</td>

<td>

<code>x %na\<-% 0</code>
</td>

</tr>

<tr>

<td>

<code>ifelse(b == 0, NA, a / b)</code>
</td>

<td>

<code>a %/0% b</code>
</td>

</tr>

</tbody>

</table>

<p>

<em>On the <a href="https://benwiseman.github.io/roperators/">package
site</a> this is an interactive taste test — you pick the line you’d
rather write, and it tells you if you’ve got good taste. →</em>
</p>

</div>

All base R, zero dependencies — just operators and helpers that say what
you mean. (Pronounced *rop-er-ators*, not *r-operators*.)

## Installation

``` r
install.packages("roperators")                       # released, from CRAN
remotes::install_github("BenWiseman/roperators")      # or the dev version
```

## Find the right tool

<div id="rop-finder">

<p>

<em>On the <a href="https://benwiseman.github.io/roperators/">package
website</a> this is an interactive finder — search by what you’re trying
to do (“join two strings”, “missing values”, “read a file”…) and jump
straight to the docs. The
<a href="https://benwiseman.github.io/roperators/reference/index.html">full
reference</a> lists everything.</em>
</p>

</div>

## At a glance

| You want…                       | Reach for                           |
|---------------------------------|-------------------------------------|
| String concat / subtract        | `%+%` / `%-%`                       |
| String repeat / count           | `%s*%` / `%s/%`                     |
| In-place maths                  | `%+=%` `%-=%` `%*=%` `%/=%` `%^=%`  |
| Fill NAs / regex edit in place  | `%na<-%` / `%regex=%` / `%regex<-%` |
| NA-aware (in)equality           | `%==%` `%>=%` `%<=%`                |
| Floating-point equality         | `%~=%` `%>~%` `%<~%`                |
| Strict (value + class) equality | `%===%`                             |
| Between (excl / incl)           | `%><%` / `%>=<%`                    |
| Not-in / xor / all-or-nothing   | `%ni%` / `%xor%` / `%aon%`          |
| String interpolation            | `f()`                               |
| Inline error fallback           | `%else%`                            |
| Safe divide / tolerance         | `%/0%` / `%+-%`                     |
| Fuzzy string match              | `%~%`                               |

## Next steps

- **[Take the 5-minute guided tour
  →](https://benwiseman.github.io/roperators/articles/nicer_roperators.html)**
- **[Browse all functions
  →](https://benwiseman.github.io/roperators/reference/index.html)**

A quick note on shared names: `%+%` is also ggplot2’s, and
`%like%`-style matching is data.table’s. If you load those too, use the
namespaced form (`roperators::%+%`) where it matters.
