[R] Modify objects in function

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Thu Jan 31 16:08:23 CET 2013


On Thu, Jan 31, 2013 at 3:00 PM, Simon Zehnder <szehnder at uni-bonn.de> wrote:
> Hi Barry,
>
> this actually a good idea, to put them together! Probably even creating an object containing both of them. Haven't thought about it before.
>

 Hadley W asked for implementations of 'unstructuring assignments' the
other day, and I bashed this out to a gist:

https://gist.github.com/4543212

 it lets you do:

 (a~b~c) = foo()

and if foo() returns a list with three components it assigns them to
a, b, and c. Equivalent to:

tmp = foo()
a=tmp[[1]]
b=tmp[[2]]
c=tmp[[3]]

whether its any use to your use case or even works properly under all
circumstances or even just serves to obfuscate things is a point for
discussion...

Barry



More information about the R-help mailing list