[R] Very simple question R5 setRefClass and Initialize
Julien Cochennec
julien.cochennec at mnhn.fr
Mon Jun 25 13:45:15 CEST 2012
Help anyone? Is this impossible? I tried to use the initFields method
but it did not change anything.
Le 25/06/2012 10:55, Julien Cochennec a écrit :
> Hi,
> New to this list, and glad I found R5 which si a great improvement to
> R for my work.
> Something seems odd anyway, when I do a setRefClass, the initialize
> method execute at the class definition.
> I would like it to execute only when an instance is created.
> How can I do that? I found no way to test if the code execution is
> when the class definition happens or when a $new instance is created.
> Thanks for your help.
> For example my class definition looks like this :
>
> mongoDbUser = setRefClass("mongoDbUser",
> fields = list(
> auth = "logical",
> host = "character",
> username = "character",
> password = "character",
> db = "character",
> connector = "mongo"
> ),
> methods = list(
> initialize = function(auth,host,username,password,db,connector){
> print("initialization")
> }
> )
> )
>
> If I execute this code, it says "initialization", but it shouldn't, I
> created no instance, right??
> I would like "initialization" to appear only when I do :
> mongoDbUser$new(...)
>
> ______________________________________________
> 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.
>
More information about the R-help
mailing list