MyNixOS website logo
Description

Additional Operators to Help You Write Cleaner R Code.

A set of additional operators and helper functions to make R code easier to read, write, and maintain. Includes string arithmetic (such as 'foo' + 'bar'), in-place reassignment operators (such as x += 1), logical operators that handle missing values, floating-point and strict ('JavaScript'-style) equality tests, 'between' operators, and 'SQL'-style pattern matching. Also provides convenience helpers for type conversion, operating-system checks, complete-cases statistics, and string manipulation, such as Oxford-comma pasting and extracting the first, last, n-th, or most common element of a vector or word in a string. The goal is to give R users, particularly those coming from other languages such as 'Python', a friendlier and more consistent syntax.

roperators

CRANversion metacrandownloads License:MIT R-CMD-check

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

Which would you rather write?

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.)

Installation

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

Find the right tool

On 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.

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 interpolationf()
Inline error fallback%else%
Safe divide / tolerance%/0% / %+-%
Fuzzy string match%~%

Next steps

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.

Metadata

Version

1.4.0

License

Unknown

Platforms (79)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    uefi
    wasip1
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-uefi
  • aarch64-windows
  • aarch64_be-none
  • arc-linux
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • sh4-linux
  • vc4-none
  • wasm32-wasip1
  • wasm64-wasip1
  • x86_64-cygwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-uefi
  • x86_64-windows