First, is there a function like 'methods', but which also shows the package
for each function?

Now, to your question.  Here is an example that is not quite the same as
what I had earlier, but exhibits some similar behavior.  Let me know if I'm
doing something wrong.

Say I want to change AIC to print "Akaike" instead of "AIC".

Here is the new function.

AIC.default <- function (object, ..., k = 2)
{
    ll <- if ("stats4" %in% loadedNamespaces())
        stats4:::logLik
    else logLik
    if (!missing(...)) {
        lls <- lapply(list(object, ...), ll)
        vals <- sapply(lls, function(el) {
            no <- attr(el, "nobs")
            c(as.numeric(el), attr(el, "df"), if (is.null(no)) NA_integer_
else no)
        })
        val <- data.frame(df = vals[2L, ], ll = vals[1L, ])
        nos <- na.omit(vals[3L, ])
        if (length(nos) && any(nos != nos[1L]))
            warning("models are not all fitted to the same number of
observations")
        val <- data.frame(df = val$df, Akaike = -2 * val$ll + k *
            val$df)
        Call <- match.call()
        Call$k <- NULL
        row.names(val) <- as.character(Call[-1L])
        val
    }
    else {
        lls <- ll(object)
        -2 * as.numeric(lls) + k * attr(lls, "df")
    }
}


Here is my session transcript, with comments to show ESS actions.

R version 3.0.0 (2013-04-03)
Done with c:/kw/.Rprofile.
R> R> options(chmhelp=FALSE, help_type="text")
R> options(STERM='iESS', str.dendrogram.last="'", editor='emacsclient.exe',
show.error.locations=TRUE)
R>
R> lm1 <- lm(Fertility ~ . , data = swiss)
R> lm2 <- update(lm1, . ~ . -Examination)
R> AIC(lm1, lm2)
    df      AIC
lm1  7 326.0716
lm2  6 325.2408
# ESS: developer active, developing stats
R> library('stats')
R> methods('AIC')
[1] AIC.default* AIC.logLik*

   Non-visible functions are asterisked
R> getAnywhere('AIC.default')
A single object matching 'AIC.default' was found
It was found in the following places
  registered S3 method for AIC from namespace stats
  namespace:stats
with value

function (object, ..., k = 2)
{
    ll <- if ("stats4" %in% loadedNamespaces())
        stats4:::logLik
    else logLik
    if (!missing(...)) {
        lls <- lapply(list(object, ...), ll)
        vals <- sapply(lls, function(el) {
            no <- attr(el, "nobs")
            c(as.numeric(el), attr(el, "df"), if (is.null(no)) NA_integer_
else no)
        })
        val <- data.frame(df = vals[2L, ], ll = vals[1L, ])
        nos <- na.omit(vals[3L, ])
        if (length(nos) && any(nos != nos[1L]))
            warning("models are not all fitted to the same number of
observations")
        val <- data.frame(df = val$df, AIC = -2 * val$ll + k *
            val$df)
        Call <- match.call()
        Call$k <- NULL
        row.names(val) <- as.character(Call[-1L])
        val
    }
    else {
        lls <- ll(object)
        -2 * as.numeric(lls) + k * attr(lls, "df")
    }
}
<bytecode: 0x066612dc>
<environment: namespace:stats>
R> # ESS: source new function C-c C-f
R> getAnywhere('AIC.default')
A single object matching 'AIC.default' was found
It was found in the following places
  registered S3 method for AIC from namespace stats
  namespace:stats
with value

<srcref: file "c:/x/bug.r@1" chars 1:16 to 27:1>
<environment: namespace:stats>
Warning message:
In file(srcfile$filename, open = "rt", encoding = encoding) :
  cannot open file 'c:/x/bug.r@1': No such file or directory
R>


On Sun, Apr 21, 2013 at 9:01 AM, Vitalie Spinu <spinuvit@gmail.com> wrote:

>
> Kevin,
>
> Is there a way to reproduce your problem with one of the S3
> methods/generics in default R packages?
>
> I am not using S3 myself and, quite frankly, I have already forgotten
> the exact caching mechanism of S3 methods. Also this mechanism might
> have been changed in 3.0.0, so a reproducible example would be very much
> welcome.
>
> Thanks,
>     Vitalie
>
>
>
>  >> Vitalie Spinu <spinuvit@gmail.com>
>  >> on Sun, 21 Apr 2013 14:01:55 +0200 wrote:
>
>  >> Martin Maechler <maechler@stat.math.ethz.ch>
>  >> on Sat, 20 Apr 2013 18:02:29 +0200 wrote:
>
>  >> On Sat, Apr 20, 2013 at 1:38 AM, Vitalie Spinu <spinuvit@gmail.com>
> wrote:
>  >>
>  >> As long as the two copies are the same, it should not matter for
>  >> anything. Why does that bother you specifically?
>  >>
>
>  >> Well, I think it should be bothering a bit.  It invalidates the
> principle
>  >> that using ESS, from the point of view of R, is as much as possible
> like
>  >> using R outside ESS  .. only better, of course.
>
>  > This is how R works. It keeps several copies of a function on some
>  > occasions. S3 is one of those.
>
>  >     Vitalie
>



-- 
Kevin Wright

	[[alternative HTML version deleted]]

