R's superassignment operator
Oct. 1st, 2009 02:22 amR's assignment operator is "<-". Typically, R functions do not have side-effects... whenever you refer to an outside variable inside a function, what you're seeing is a copy, shadowing the original... which means that you should return all the information you want to keep.
However, I just discovered that there is a superassignment operator, "<<-", which enables side-effects.
However, I just discovered that there is a superassignment operator, "<<-", which enables side-effects.
> m <- 5
> f <- function(){ m <<- 10 }
>
> m
[1] 5
> f()
> m
[1] 10
(no subject)
Date: 2009-10-01 01:38 pm (UTC)(no subject)
Date: 2009-10-01 07:15 pm (UTC)(no subject)
Date: 2009-10-01 07:46 pm (UTC)(no subject)
Date: 2009-10-01 07:51 pm (UTC)(no subject)
Date: 2009-10-01 07:19 pm (UTC)You can still write your code to be side-effect-free, and easily verify it by searching for "<<-".
(no subject)
Date: 2009-10-02 07:26 am (UTC)(Also, re: top level post: "arrrrrgghhhhhj, EVERYTHING IS RUINED FOREVER." Like gwillen's reaction, only a billion times worse.)
(no subject)
Date: 2009-10-01 08:59 pm (UTC)(no subject)
Date: 2009-10-01 09:07 pm (UTC)I often find the list vs vector distinction annoying, and many commands are named funny. e.g. 'assert' is 'stopifnot'.
Somewhat to my surprise, I've found a few places where it's less annoying than Matlab, e.g. the ability to write things like: f(5)[1].