bcast: Compact mapply() a la' broadcast() from Julia

Description Usage Arguments Value See Also Examples

View source: R/bcast.R

Description

Inspired by the dot syntax from Julia's broadcast, execute mapply() with a convenient shortand.

Usage

1
2
bcast(f, x, ..., simplify = FALSE)
.(f, x, ..., simplify = FALSE)

Arguments

f

Function.

x

First argument to vectorize over.

...

a list of additional arguments to FUN. See mapply.

simplify

Boolean, same as SIMPLIFY in mapply.

Value

List (if simplify = FALSE) or array (if simplify = TRUE).

See Also

https://github.com/robertschnitman/afp, mapply, broadcast from Julia: https://docs.julialang.org/en/v0.6.1/manual/arrays/#Broadcasting-1

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
set.seed(1)
a <- matrix(1:9, 3, 3)
b <- 20:22
c <- matrix(rnorm(9), 3,)
bcast(`/`, a, b, simplify = TRUE) # matrix.
bcast(`/`, a, b, c, simplify = TRUE) # If a warning occurs, output may be list.

# Alternate syntax
.(`/`, a, b, simplify = TRUE) # matrix.
.(`/`, a, b, c, simplify = TRUE) # If a warning occurs, output may be list.

robertschnitman/afp documentation built on Aug. 9, 2020, 9:46 a.m.