0

Imagine that I have a function:

foo <- function(){
i <- 1
i <- i + 1
return
}

And then I want to be able to call and change i from outside the function without returning it:

print(i)

Should return 2

i <- i + 1; print(i)

Should return 3

Thanks

Miguel Santos
  • 1,806
  • 3
  • 17
  • 30
  • 3
    Please don't use global variables; it's bad style. – Hong Ooi Dec 10 '19 at 15:11
  • style is overrated – Miguel Santos Dec 10 '19 at 15:12
  • @Aziz Not really, I have tried it and it does not work when you change the variable inside the same or other function – Miguel Santos Dec 10 '19 at 15:17
  • @Aziz You closed the question anyway uh? – Miguel Santos Dec 10 '19 at 15:24
  • Right now, the question looks like a duplicate to the one linked by Aziz. If you think that your question is different, please edit it and explain why your question is different and what went wrong when you tried the solutions from the other question (with code you've tried and the unexpected output). I will reopen the question or someone else will once you've done that. – acylam Dec 10 '19 at 16:14

0 Answers0