r-lib / R6

Encapsulated object-oriented programming for R
https://R6.r-lib.org
Other
407 stars 56 forks source link

R6 multiplte ctor #60

Closed agstudy closed 9 years ago

agstudy commented 9 years ago

Is there multiple constructor feature within R6? initialize overloading ?

wch commented 9 years ago

I'm not sure what you mean. Can you supply an example?

agstudy commented 9 years ago

I mean that the class can have one than more initializer: Something like :

    initialize = function(x){
           .....
    },  
   ## second ctor with 2 parameters 
   initialize = function(x,y){
           .....
    },

The idea is to create my object using multi constructors;

Obj$new(1)
or
Obj$new(1,2)

I know that I can deal with this using something like :

       initialize = function(...){
           ## deal with args here
      }

But I am just asking in case there already is built-in feature that deal with this.

wch commented 9 years ago

Sorry, R in general doesn't do that sort of function overloading. The version of your function with ... is probably the way to go.

agstudy commented 9 years ago

I know. I think we should get better well-typed behavior. S4 looks better armed for this feature than R6. Anyway thank you for your feedback.