In R, when I want to modify global variable in function, I do it like this:
myfun <- function ()
{
a <<- 1
# .. later.. more complex code
a <<- 2
a <<- 3
}
I don't like having to specify <<-
instead <-
all the time. I am not used to it and I always forget. Is it in R somehow possible to declare variable as global just once? E.g. something along the lines:
myfun <- function ()
{
global a
a <- 1 # modify global var
# .. later.. more complex code
a <- 2 # modify global var
a <- 3 # modify global var
}
PS: I do not see how this would be a duplicate of the proposed question. Please expand in an answer to explain.