Answer by Rtist for How do you use "
I use it in order to change inside purrr::map() an object in the global environment.a = c(1,0,0,1,0,0,0,0)Say I want to obtain a vector which is c(1,2,3,1,2,3,4,5), that is if there is a 1, let it 1,...
View ArticleAnswer by Carlos Cinelli for How do you use "
The <<- operator can also be useful for Reference Classes when writing Reference Methods. For example:myRFclass <- setRefClass(Class = "RF", fields = list(A = "numeric", B = "numeric", C =...
View ArticleAnswer by Matthew Wise for How do you use "
On this subject I'd like to point out that the <<- operator will behave strangely when applied (incorrectly) within a for loop (there may be other cases too). Given the following code:fortest...
View ArticleAnswer by hadley for How do you use "
<<- is most useful in conjunction with closures to maintain state. Here's a section from a recent paper of mine:A closure is a function written by another function. Closures areso-called because...
View ArticleAnswer by Shane for How do you use "
It helps to think of <<- as equivalent to assign (if you set the inherits parameter in that function to TRUE). The benefit of assign is that it allows you to specify more parameters (e.g. the...
View ArticleAnswer by lcgong for How do you use "
f <- function(n, x0) {x <- x0; replicate(n, (function(){x <<- x+rnorm(1)})())}plot(f(1000,0),typ="l")
View ArticleAnswer by Dirk is no longer here for How do you use "
One place where I used <<- was in simple GUIs using tcl/tk. Some of the initial examples have it -- as you need to make a distinction between local and global variables for statefullness. See for...
View ArticleHow do you use "
I just finished reading about scoping in the R intro, and am very curious about the <<- assignment.The manual showed one (very interesting) example for <<-, which I feel I understood. What...
View Article
More Pages to Explore .....