[R] change function scope?

From: James McCreight <jlmccreight_at_gmail.com>
Date: Thu, 26 May 2011 15:09:25 -0600


I'm still getting used to R's scoping. I've run into the following situation

value=0
thefunction <- function() print( value ) somefunction <- function() { value=99; thefunction() } somefunction()

now, I understand that somefunction() returns 0 because thefunction() was defined with value=0 in its parent envrionment, it dosent look at all in the environment of somefunction. My question is can I re-scope thefunction in the somefunction environment?? (So that somefunction() returns 99). I've tried various uses of eval() and assign() with their keywords in the definition of somefunction and have had no luck at all.

I do see that i could define thefunction in some external file and source it inside somefunction, but that seems clumsy.

thanks!!

James

        [[alternative HTML version deleted]]



R-help_at_r-project.org 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. Received on Thu 26 May 2011 - 21:11:00 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 27 May 2011 - 00:50:10 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive