[R] Question on closure (lexical scoping) and encapsulation

Aleksey Naumov naumov at acsu.buffalo.edu
Tue Jun 13 21:47:18 CEST 2000


Dear R users,

I have two related questions about scoping and data encapsulation.

One is fairly specific - I am looking at "scoping.R" which is used in
demo(scoping) - it's an example of lexical scoping and encapsulation.
Where is the 'total' stored? It is not an attribute in 'ross' or
'robert'
however, functions like balance() have access to it.
Is it more or less like a private class member in C++, so that it's not
possible to access it from outside of class? Or is it possible to access
it
in some way?

The second one is more general - what is the best way to encapsulate
some
user data with an object like a data frame? I'd like to keep a few user
attributes with a data frame... I can think of 3 possibilities, but I
don't know if there's a good and reliable standard way:
    - I tried using attributes(), but found out that subset() gets rid
of
user attributes and didn't see an easy way to reset them on a subsetted
frame
(doing it one by one is not an option, and mostattributes() doesn't seem
to
be there anymore)
    - Something like the example used in 'scoping.R'
    - Using class()? Documentation for class() talks about providing
methods
for generic functions, but I didn't see an example of accessing
user-defined
data members/attributes.

Many thanks!

Aleksey




-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list