Thanks Gabor!

I changed the class to "ANY" and it works now. Should there be an "as"
method for coercing instantiatedProtoMethod to function, or would that lose
the "proto" nature of the object?

(Yvonnick, I checked in the change to r-forge
https://r-forge.r-project.org/R/?group_id=761)

--John

On Fri, May 13, 2011 at 9:33 AM, Gabor Grothendieck <ggrothendi...@gmail.com
> wrote:

> On Fri, May 13, 2011 at 7:52 AM, John Verzani <verz...@math.csi.cuny.edu>
> wrote:
> > Dear Yvonnick and Gabor,
> > I use a different implementation for each, but this gave me some place to
> > look. For gradio for gWidgetsRGtk2 I decoupled the handler call from the
> > widget so replacing radio buttons was easier. The R5 class I made, for
> some
> > reason, doesn't play nicely with this proto object. Here is a simplified
> > example:
> > library(proto)
> > a <- setRefClass("Test",
> >                  fields=list(
> >                    o = "function"
> >                    ),
> >                  methods=list(
> >                    initialize=function(o) {
> >                      o <<- o
> >                    }))
> > example = proto(
> >  create = function(.) {
> >    a$new(.$onChoice)
> >  },
> >  onChoice = function(.,h,...) {
> >    print("hi")
> >  }
> > )
> >
> > When setting the "o" property R tries coercion to a function and you get
> > this error.
> > Gabor, any thoughts? This deep dark magic is one of your many
> specialities.
>
> The class vector of .$onChoice is c("instantiatedProtoMethod",
> "function").  It seems the reference class mechanism won't let you
> refer to it as "function".  Also, the initialize method needs to have
> an appropriate return value.
>
> This seems to work for me where the ## lines are new or modified:
>
> library(proto)
> setClass("instantiatedProtoMethod")
> a <- setRefClass("Test",
>                 fields=list(
>                    o = "instantiatedProtoMethod" ##
>                    ),
>                 methods=list(
>                   initialize=function(o) {
>                      initFields(o = o) ##
>                    }))
>
> example = proto(
>  create = function(.) {
>   a$new(.$onChoice)
>  },
>  onChoice = function(.,h,...) {
>   print("hi")
>  }
> )
> example$create()$o() ##
>
> --
> Statistics & Software Consulting
> GKX Group, GKX Associates Inc.
> tel: 1-877-GKX-GROUP
> email: ggrothendieck at gmail.com
>



-- 
John Verzani
Chair, Department of Mathematics
College of Staten Island, CUNY
verz...@math.csi.cuny.edu

        [[alternative HTML version deleted]]

_______________________________________________
R-SIG-GUI mailing list
R-SIG-GUI@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-gui

Reply via email to