On 02/27/2013 07:30 PM, David Winsemius wrote: > On Feb 27, 2013, at 10:16 AM, Bert Gunter wrote: > >> Some additional comments inline below to add to David's >> clarifications, proffered largely in response to the poster's remark >> about coming to R from another language. >> >> On Wed, Feb 27, 2013 at 9:44 AM, David Winsemius <dwinsem...@comcast.net> >> wrote: >>> On Feb 27, 2013, at 1:11 AM, Zé Miguel wrote: >>> >>>> Dear David, >>>> >>>> thanks for your reply. Sorry for the ambiguous example. I guess the get() >>>> will do it, but I still have a question regarding the parent frame. If I >>>> declare both function g and f in the global environment: >>>> >>>> g <- function() >>>> { >>>> get(N,envir = ???) >>>> write(N) >>>> } >>>> >>>> f<-function() >>>> { >>>> N<-99 >>>> g() >>>> } >> While David shows you below how you **can** do this, I would suggest >> that you **don't.** >> >> The reason is that R largely follows a functional programming paradigm >> (e.g like Scheme or Lisp, for those in the know). Among other things, >> this means that essentially a function environment should be its own >> little world, and that anything needed for it to do its job in that >> world should be explicitly passed to it as a function argument. The >> practical danger of circumventing this paradigm and reaching back into >> a parent or global environment is that you don't know what will be >> there. Functions can be called by other functions and, if created to >> serve a purpose as an independent entity, might be called under >> circumstances entirely unforeseen by the function author. >> >> There are certainly situations where one may wish to violate this >> dictum, and I am sure R experts could provide compelling examples of >> them. But for the great mass of us unwashed, I think hewing to the R >> functional paradigm is a safer and more sensible course. > Oh, yes. I quite agree. I was taking that as an opportunity to illustrate why > the N of 99 in inside his f() was NOT in the global environment (as it > appeared that JMD expected). I was not suggesting that he try to shoehorn R > into behaving like SAS or SPSS or BASIC. or Minitab or .... where everything > is global. > I get your point. I will avoid it in the future, but will definitely need it for this particular problem. The issue was solved with get(). Thanks for guiding me through the beautiful world of R. An additional comment from Mark Leeds was also quite helpful:
> hadley wickham has a whole set of documentation ( he's writing a book > ) titled "devtools" on github. > > john fox has something on scope from back in 2003 but it's still good. > ( on his website ) > > www.obeautifulcode.com <http://www.obeautifulcode.com> has an archive > called "how R researches and finds stuff" that is exactly talking > directly about scope but in an indirect way it is. Thanks a lot to him too -- Zé Miguel _______________________________ JM Delgado Reichenberger Str. 52 10999 Berlim Alemanha t(d):+49 30 841 18 127 m(d):+49 176 9633 92 56 m(p):+351 91 671 07 08 [[alternative HTML version deleted]]
______________________________________________ R-help@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.