broadcaster: Check or Set if an Array is a Broadcaster

View source: R/broadcaster.R

broadcasterR Documentation

Check or Set if an Array is a Broadcaster

Description

broadcaster() checks if an array has the "broadcaster" attribute.
⁠broadcaster()<-⁠ sets or un-sets the class attribute "broadcaster" on an array.

The broadcaster class attribute exists purely to overload the arithmetic, Boolean, bit-wise, and relational infix operators, to support broadcasting.
This makes mathematical expressions with multiple variables, where precedence may be important, far more convenient.
Like in the following calculation:
x / (y + z)

See broadcast_operators for more information.

Usage

broadcaster(x)

broadcaster(x) <- value

Arguments

x

object to check or set.
Only S3 vectors and arrays are supported, and only up to 16 dimensions.

value

set to TRUE to make an array a broadcaster, or FALSE to remove the broadcaster class attribute from an array.

Value

For broadcaster():
TRUE if an array or vector is a broadcaster, or FALSE if it is not.

For ⁠broadcaster()<-⁠:
Returns nothing, but sets (if right hand side is TRUE) or removes (if right hand side is FALSE) the "broadcaster" class attribute.

Examples


# maths ====

x <- 1:10
broadcaster(x) <- TRUE

y <- 1:10
broadcaster(y) <- TRUE

x + y / x
x + 1 # mathematically equivalent to the above, since x == y
(x + y) / x
2 * x/x # mathematically equivalent to the above, since x == y

dim(x) <- c(10, 1)
dim(y) <- c(1, 10)

x + y / x
(x + y) / x

(x + y) * x


# relational operators ====
x <- 1:10
y <- array(1:10, c(1, 10))
broadcaster(x) <- TRUE
broadcaster(y) <- TRUE

x == y
x != y
x < y
x > y
x <= y
x >= y


broadcast documentation built on Sept. 15, 2025, 5:08 p.m.