I'd say that was pretty clearly a bug in stats4 (which as I recall was
needed to get around the scoping awkwardnesses of S4).
But could you not write a logLik method for your class? E.g.
> logLik.bar <- function(object, ...) structure(pi,
class="logLik", df=1)
> AIC(bar.tmp)
[1] -4.283185> library(stats4)
> AIC(bar.tmp)
[1] -4.283185
On Thu, 6 Dec 2007, Spencer Graves wrote:
> Hello:
>
> How can I work around the conflict between the S3 and S4
> illustrated in the example below? I'm developing a package that
> requires a function in 'stats4', but when 'stats4' is
attached, it
> breaks my AIC function. I could give my AIC function another name so it
> no longer uses the generic dispatch, but I wonder if there is another way.
>
> Thanks,
> Spencer Graves
> ################################
> bar.tmp <- structure(1, class = "bar")
> AIC.bar <- function(object, ..., k=2) {
> 3
> }
>
> > AIC(bar.tmp)
> [1] 3
> > library(stats4)
> > AIC(bar.tmp)
> Error in UseMethod("logLik") : no applicable method for
"logLik"
> > detach("package:stats4")
> > AIC(bar.tmp)
> [1] 3
> > objects()
> [1] "AIC.bar" "bar.tmp"
> > sessionInfo()
> R version 2.6.1 (2007-11-26)
> i386-pc-mingw32
>
> locale:
> LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
> States.1252;LC_MONETARY=English_United
> States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252
>
> attached base packages:
> [1] stats graphics grDevices utils datasets methods base
>
> loaded via a namespace (and not attached):
> [1] stats4_2.6.1
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595