pipe_arithmetic: Pipe-friendly arithmetic helpers

pipe_arithmeticR Documentation

Pipe-friendly arithmetic helpers

Description

A set of simple, vectorized, pipe-friendly arithmetic functions for transforming numeric data in pipelines. These helpers make common operations like multiplication, division, addition, subtraction, exponentiation, and reciprocals clearer when using the native pipe ⁠|>⁠.

Usage

reciprocal(x)

pow(x, p)

add(x, k)

subtract(x, k)

mult(x, k)

divide(x, k)

Arguments

x

A numeric vector or scalar.

p

A numeric scalar exponent (for pow).

k

A numeric scalar for addition, subtraction, multiplication, or division.

Details

All functions are vectorized and support numeric vectors, scalars, or compatible objects. They are designed to improve the readability of transformation pipelines.

Value

A numeric vector or scalar resulting from the transformation.

Examples

x <- c(1, 2, 3)

# Multiplication and division
x |> mult(10)
x |> divide(2)

# Addition and subtraction
x |> add(5)
x |> subtract(1)

# Reciprocal
x |> reciprocal()

# Power
x |> pow(2)

# Combined use in pipelines
x |>
  mult(2) |>
  add(3) |>
  reciprocal()


doBy documentation built on Dec. 2, 2025, 9:08 a.m.