| broadcaster | R Documentation |
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.
broadcaster(x)
broadcaster(x) <- value
mbroadcasters(nms, value, env = NULL)
bcr(x)
bcr(x) <- value
x |
object to check or mark. |
value |
set to |
nms |
a character vector of variable names. |
env |
the environment where to look for the variable names specified in |
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.
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.
broadcast_operators
# 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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.