[R] How do I create an object in the Global environment from a function

Charilaos Skiadas skiadas at hanover.edu
Thu Dec 14 14:40:01 CET 2006


On Dec 14, 2006, at 7:42 AM, Rainer M Krug wrote:

> myfunc <- function() b <<- 34

I would add a warning here. It is generally not a good idea for a  
function to have side-effects. In this case, if there is a globally  
defined value for b already, it will be overwritten. If this function  
is in a package say, and someone else uses it, or you use it after a  
very long time and have forgotten its internals and the fact that  
it's messing with the Global Environment, this might lead to some  
bugs that are really hard to spot.

> Rainer

Haris



More information about the R-help mailing list