subset-.result: DBind, '[<-.result'

Description Usage Arguments Details Value References Examples

Description

Assign elements of a list to multiple variable names in current namespace.

Usage

1
2
## S3 replacement method for class 'result'
x[...] <- value

Arguments

x

function first argument

...

function additional argument

value

values to be assigned in parent frame

Details

This operation mimics the behavior of destructuring-bind (Lisp), sequence unpacking (Python), and deal (MATLAB). This R implementation is taken directly from G. Grothendieck's implementation of List as posted in R-help[1] but renamed as DBind. While returning multiple values from a function is considered unfunctional, the idea is to compose multiple operations (funciton invocation and subsequent assignment of list contents) into one.

Value

Produces side effect of assigning multiple values in the parent frame.

References

[1] https://stat.ethz.ch/pipermail/r-help/2004-June/053343.html

Examples

1
2
3
4
5
6
7
## As provided by G. Grothendieck in R-help:
DBind[QR,,QRaux]  <- qr(c(1,1:3,3:1))
DBind[,Green,Blue]  <- col2rgb("aquamarine")

## Additional examples:
x <- list(a=1, b=2)
DBind[a, b] <- x

stakahama/Rfunctools documentation built on June 8, 2021, 10:25 p.m.