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 or vector is marked as a "broadcaster".
bcr() is a short-hand alias for broadcaster().

⁠broadcaster()<-⁠ (or ⁠bcr()<-⁠) marks or un-marks the object as a "broadcaster".

mbroadcasters() marks or un-marks multiple objects in an environment as broadcaster.
mbroadcasters() may be more memory efficient for large arrays than ⁠broadcaster()<-⁠, as mbroadcasters() calls ⁠class(x)<-⁠ directly in the given environment.

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

mbroadcasters(nms, value, env = NULL)

bcr(x)

bcr(x) <- value

Arguments

x

object to check or mark.
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.

nms

a character vector of variable names.

env

the environment where to look for the variable names specified in nms.
If NULL, the environment from which the function was called is used.

Value

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

For ⁠broadcaster()<-⁠:
Returns nothing, but marks (if right hand side is TRUE) or un-marks (if right hand side is FALSE) the object as a "broadcaster".

For mbroadcasters():
Returns nothing, but marks (if value is TRUE) or un-marks (if value is FALSE) the objects as broadcasters.
If value = TRUE, objects that cannot become a broadcaster or are already a broadcaster will be ignored.
If value = FALSE, objects that are not broadcasters (according to broadcaster()) will be ignored.

Note

The 'broadcaster' class will make arithmetic and relational operators operate with broadcasting.
Functions that rely on non-broadcasted functionality of these operators will produce unexpected results.
Thus functions like pmin() and pmax(), and some functions from the 'tinyplot' package, are not compatible with 'broadcaster' vectors/arrays.
Please ensure an object is not a 'broadcaster' before applying these functions on it.

See Also

broadcast_operators

Examples


# maths ====

x <- 1:10
y <- 1:10
dim(x) <- c(10, 1)
dim(y) <- c(1, 10)
broadcaster(x) <- TRUE
broadcaster(y) <- TRUE



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




# maths ====

x <- sample(1:10)
y <- sample(1:10)
dim(x) <- c(10, 1)
dim(y) <- c(1, 10)
mbroadcasters(c("x", "y"), TRUE)



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

(x + y) * x


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

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



broadcast documentation built on Aug. 20, 2026, 9:08 a.m.