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

About this list Date view Thread view Subject view Author view Other groups

Subject: [R] Question on closure (lexical scoping) and encapsulation
From: Aleksey Naumov (naumov@acsu.buffalo.edu)
Date: Wed 14 Jun 2000 - 05:47:18 EST


Message-ID: <39468FC6.B041ED26@acsu.buffalo.edu>

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@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b25 : Mon 17 Jul 2000 - 12:33:22 EST