[R] object orientation using local procedures

Thomas Petzoldt petzoldt at rcs.urz.tu-dresden.de
Wed Nov 1 21:50:45 CET 2000


Hi R-folks,

R is a great data analysis system and yes, there is some object
orientation (OO). My problem coming from other OO-languages like JAVA
is, that I have problems constructing "objects", which contain data
(object properties) and code (methods). Is there any mechanism like the
"self" or "my" in other languages.

In the R introduction I found an example, like:

test <- function() {
   a<-1,
   b<-2,
   list (
      geta = function () a,
      seta = function (newa) a<<-newa,
    )
}

Now I can create an instance of test:
> aTest <- test()
and call the functions 
> aTest$geta()
and e.g.
> aTest$seta(5)
or
> aTest$product()

with the expected results. Now, as the "object" becomes more complex I
want to call local functions, e.g. in the extended object:

test2 <- function() {
   a<-1,
   b<-2,
   list (
      geta = function () a,
      seta = function (newa) a<<-newa,
      product = function() a*b,
      localcall = function() product()   # a function which *should
call* a function of the "object"
   )
}

where the function localcall() should call the local function product().
Written as above, this will not work, as the function product() exists
in another environment. Is there a straightforward solution for this
(common OO) problem?

Thanks in advance!

Thomas Petzoldt

--
Thomas Petzoldt
Institute of Hydrobiology
Dresden University of Technology
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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