[R] Very simple question R5 setRefClass and Initialize
Julien Cochennec
julien.cochennec at mnhn.fr
Mon Jun 25 10:55:00 CEST 2012
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(...)
More information about the R-help
mailing list