This syntax
  Omega(x = 1)
seems weird.  How do you know that this call should refer back to the Model
object and not some other hypothetical Model2 object?  The code you're
defining should make something like this work
  Omega(Model)(x=1)
where you can see the direct dependence on the Model object.

(unrelated: One experience from Bioconductor, is that it is good to have
explicit constructors for S4 objects instead of using new("...").)

Best,
Kasper

On Mon, Mar 28, 2016 at 2:09 PM, Glenn Schultz <glennmschu...@me.com> wrote:

> All,
> I am creating a mortgage prepayment model package.  The idea is to create
> a class FRMModelFunction and each slot in the class is a function that may
> be use in the prepayment. So I would like to create a generic and method
> that will allow me to call the slot by name.  However, I think that I am
> missing something in my setup
>
> If I run the below code I can do the following
>
> Omega(Model) which returns the function
>
> Omega <- Omega(Model) which then assigns the function and allows me to
> pass values and get a result from Omega(x = 1)
>
> However I can also get a result by directly accessing the slot
>
> Model@Omega(x=1)
>
> What I want to do is set a generic and method so that I can do the
> following
>
> Omega(x=1)
>
> The below is close but still not what I would like to have.  Is what  I
> have described possible and if so what have I missed?
>
> Glenn
>
>
> setGeneric("Omega", function(object,...) {standardGeneric("Omega")})
>
>  setMethod("Omega", signature = "FRMModelFunction",
>            definition = function(object){object@Omega})
>
>  setClass("FRMModelFunction",
>           representation(
>             Omega = "function"))
>
>  Model <- new("FRMModelFunction",
>            Omega = function(x = numeric()) {return(max(0, min(1, x)))}
>            )
> ______________________________________________
> R-package-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>

        [[alternative HTML version deleted]]

______________________________________________
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel

Reply via email to