Methods for objects inheriting from lme (nlme package)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Methods for objects inheriting from lme (nlme package)

Johannes Ranke-2
Dear R developers,

One function in my mkin package [1] returns an object that is originally
created by nlme(), but contains some additional information. Its class is
c("mmkin.nlme", "nlme", "lme").

Now I would like to use the anova() method for lme objects for comparing such
S3 objects. Unfortunately, anova.lme currently does not check for inheritance,
but checks the  first element of the class attribute (as obtained by
data.class()) against a hardcoded list of classes in order to decide if it
will work or not.

Therefore, I created a bug report [2], containing a patch [3] for nlme that
makes anova.lme check for inheritance.

Encouraged by a kind comment by Elin Waring in the BTS, I have now revisited
my bug report, and discovered that the help page for data.class() claims that
its return value (the first element of the class attribute vector) is "what is
typically useful for method dispatching".

However, I think that this use case illustrates that it would be useful not
only to check for the primary class, but rather for class inheritance.

Do you agree that it is preferable for the S3 method to check for inheritance
instead of checking against a hardcoded list in this case?

Kind regards,

Johannes Ranke


[1]  https://github.com/jranke/mkin/blob/master/R/nlme.mmkin.R
[2]  https://bugs.r-project.org/bugzilla/show_bug.cgi?id=17761
[3]  https://bugs.r-project.org/bugzilla/attachment.cgi?id=2578

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Methods for objects inheriting from lme (nlme package)

Johannes Ranke-2
Am Montag, 20. Juli 2020, 11:12:25 CEST schrieb Johannes Ranke:

> Dear R developers,
>
> One function in my mkin package [1] returns an object that is originally
> created by nlme(), but contains some additional information. Its class is
> c("mmkin.nlme", "nlme", "lme").
>
> Now I would like to use the anova() method for lme objects for comparing
> such S3 objects. Unfortunately, anova.lme currently does not check for
> inheritance, but checks the  first element of the class attribute (as
> obtained by data.class()) against a hardcoded list of classes in order to
> decide if it will work or not.
>
> Therefore, I created a bug report [2], containing a patch [3] for nlme that
> makes anova.lme check for inheritance.
>
> Encouraged by a kind comment by Elin Waring in the BTS, I have now revisited
> my bug report, and discovered that the help page for data.class() claims
> that its return value (the first element of the class attribute vector) is
> "what is typically useful for method dispatching".
>
> However, I think that this use case illustrates that it would be useful not
> only to check for the primary class, but rather for class inheritance.
>
> Do you agree that it is preferable for the S3 method to check for
> inheritance instead of checking against a hardcoded list in this case?
>
> Kind regards,
>
> Johannes Ranke
>
>
> [1]  https://github.com/jranke/mkin/blob/master/R/nlme.mmkin.R
> [2]  https://bugs.r-project.org/bugzilla/show_bug.cgi?id=17761
> [3]  https://bugs.r-project.org/bugzilla/attachment.cgi?id=2578

P.S.: I have updated the patch [4] based on comments provided by Sebastian
Meyer.

[4] https://bugs.r-project.org/bugzilla/attachment.cgi?id=2656
        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel