inplace: General In-place Modifier Operator

inplaceR Documentation

General In-place Modifier Operator

Description

The x %:=% f operator performs in-place modification of some object x with a function f.

For example this:

mtcars$mpg[mtcars$cyl > 6] <- mtcars$mpg[mtcars$cyl>6]^2

Can now be re-written as:

mtcars$mpg[mtcars$cyl > 6] %:=% \(x) x^2

Usage

x %:=% f

Arguments

x

a variable.

f

a (possibly anonymous) function to be applied in-place on x. The function must take one argument only.

Value

This operator does not return any value:
It is an in-place modifier, and thus modifies the object directly.

See Also

tinycodet_dry

Examples

set.seed(1)
object <- matrix(rpois(10, 10), ncol = 2)
print(object)
y <- 3
object %:=% \(x) x + y # same as object <- object + y
print(object)


tinycodet documentation built on Sept. 12, 2024, 7:03 a.m.

Related to inplace in tinycodet...