Zhong-Yuan Zhang
2013-Nov-05 10:42 UTC
[R] Function does not see variables outside the function
Dear experts: In MATLAB, functions cannot see variables outside the functions. However, in R, the functions can do that. Is there any settings that can disable this ability of functions? Many thanks for your kind help. Best Regards Always. [[alternative HTML version deleted]]
Rui Barradas
2013-Nov-05 12:25 UTC
[R] Function does not see variables outside the function
Hello, I believe the answer is no. Functions will first look in their environment, and then in the parent frame, i.e., outside the function. Hope this helps, Rui Barradas Em 05-11-2013 10:42, Zhong-Yuan Zhang escreveu:> Dear experts: > > In MATLAB, functions cannot see variables outside the > > functions. However, in R, the functions can do that. Is there > > any settings that can disable this ability of functions? > > Many thanks for your kind help. > > Best Regards Always. > > [[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. >
Carl Witthoft
2013-Nov-05 12:54 UTC
[R] Function does not see variables outside the function
Why would you want to impose this restriction? Perhaps if you explain what you are trying to do, we can suggest approaches that will satisfy your specific needs. (note- one can always redefine whatever variables are to be "excluded." E.g. to keep the body of a function from referring to 'foo' in the calling environment, just add the line 'foo<-NA' inside the function) Zhong-Yuan Zhang wrote> In MATLAB, functions cannot see variables outside the > > functions. However, in R, the functions can do that. Is there > > any settings that can disable this ability of functions? > > > ______________________________________________> R-help@> 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.-- View this message in context: http://r.789695.n4.nabble.com/Function-does-not-see-variables-outside-the-function-tp4679762p4679768.html Sent from the R help mailing list archive at Nabble.com.