Global variables in R

Alphaneo picture Alphaneo · Aug 6, 2009 · Viewed 148.6k times · Source

I am poking into the manuals, I wanted to ask the community: How can we set global variables inside a function?

Answer

Dirk Eddelbuettel picture Dirk Eddelbuettel · Aug 6, 2009

As Christian's answer with assign() shows, there is a way to assign in the global environment. A simpler, shorter (but not better ... stick with assign) way is to use the <<- operator, ie

    a <<- "new" 

inside the function.