Are accessors a fancy feature that do not work?

I wanted to use accessor functions in a R refclass to hide the classes
implementation where I am using sqlite.

What I did observe is, that if I access in a method any of the fields
(in the example below field .data in method printExample) all the
accessor functions are called (even those not accessed by the function
: in this case funnydata is not accessed).

That means if any of the accessor functions is slow (in the example
the funnydata accessor sleeps for 3 s) all the fields and all
functions accessing any fields will be slow.
In the example below accessing .data or calling printExample will take 3s.

It's easy enough not to use accessor functions, so not a big deal.
Still, I lost quite a bit of time wondering what is happening.



Test <-setRefClass("Test",
                   fields = list( .data = "list",
                                  funnydata = function(x){
                                    Sys.sleep(3)
                                    if(missing(x)){
                                      Sys.sleep(3)
                                    }
                                  }
                   ),
                   methods = list(
                     initialise=function(){ .data <<- list(a="a")},

                     printExample = function(){
                       print("print Example")
                       print(.data)}
                     )
)

test<-Test()
test$printExample()
test$.data

-- 
Witold Eryk Wolski

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Reply via email to