[R] How do I create an object in the Global environment from a function
Hi all, Say I have created an object b in my function myfunc - function() b - 34 How can I make b an object in the Global environment and not just in the environment of myfunc? Thanks, Tim __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How do I create an object in the Global environment from a function
[EMAIL PROTECTED] wrote: Hi all, Say I have created an object b in my function myfunc - function() b - 34 myfunc - function() b - 34 - Rainer How can I make b an object in the Global environment and not just in the environment of myfunc? Thanks, Tim __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation Biology (UCT) Department of Conservation Ecology and Entomology University of Stellenbosch Matieland 7602 South Africa Tel:+27 - (0)72 808 2975 (w) Fax:+27 - (0)86 516 2782 Fax:+27 - (0)21 808 3304 (w) Cell: +27 - (0)83 9479 042 email: [EMAIL PROTECTED] [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How do I create an object in the Global environment from a function
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 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How do I create an object in the Global environment from a function
Please note that help(-) says: The operators '-' and '-' cause a search to made through the environment for an existing definition of the variable being assigned. If such a variable is found (and its binding is not locked) then its value is redefined, otherwise assignment takes place in the global environment. Thus, if you really want to make sure to assign it to the global environment you should do: assign(b, value, envir=globalenv()) /Henrik On 12/14/06, Rainer M Krug [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: Hi all, Say I have created an object b in my function myfunc - function() b - 34 myfunc - function() b - 34 - Rainer How can I make b an object in the Global environment and not just in the environment of myfunc? Thanks, Tim __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation Biology (UCT) Department of Conservation Ecology and Entomology University of Stellenbosch Matieland 7602 South Africa Tel:+27 - (0)72 808 2975 (w) Fax:+27 - (0)86 516 2782 Fax:+27 - (0)21 808 3304 (w) Cell: +27 - (0)83 9479 042 email: [EMAIL PROTECTED] [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.