The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
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[@]metanet.ch.
Small, friendly operators and helpers that let your R code read the way you already think it.
| base R | roperators ← cleaner |
|---|---|
paste0(“Hi”, name, “, you have”, n)
|
f(“Hi {name}, you have {n}”)
|
c(1, NA, 3) == c(1, NA, 4)
|
c(1, NA, 3) %==% c(1, NA, 4)
|
isTRUE(all.equal(0.1 + 0.1 + 0.1, 0.3))
|
(0.1 + 0.1 + 0.1) %~=% 0.3
|
x[is.na(x)] <- 0
|
x %na<-% 0
|
ifelse(b == 0, NA, a / b)
|
a %/0% b
|
On the package site this is an interactive taste test — you pick the line you’d rather write, and it tells you if you’ve got good taste. →
All base R, zero dependencies — just operators and helpers that say what you mean. (Pronounced rop-er-ators, not r-operators.)
install.packages("roperators") # released, from CRAN
remotes::install_github("BenWiseman/roperators") # or the dev versionOn the package website 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 full reference lists everything.
| 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 | %~% |
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.
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.