From mtmorgan at fhcrc.org  Tue May 16 01:40:49 2006
From: mtmorgan at fhcrc.org (Martin Morgan)
Date: Mon, 15 May 2006 16:40:49 -0700
Subject: [Rd] R CMD check does not remove all S4 methods defined in examples
Message-ID: <6phslna501q.fsf@gopher3.fhcrc.org>

Methods for generics created in '\example{}' sections of Rd files are
not entirely removed at the end of the example. This is because the
methods package caches these (in the environment returned by
getGeneric("initialize"), for the example below) as well as storing
their definition in the global environment.

The following would be derived from example code in pkg/man/eg1.Rd and
pkg/man/eg2.Rd. 'initialize' created for the first example persists in
the second, leading eventually (during R CMD check) to

> a <- new("A")
Shouldn't be here
Error in initialize(value, ...) : initialize method returned an object of class "NULL" instead of the required class "A"

[standard code and comments from pkg-Ex.R removed]
### * eg1

flush(stderr()); flush(stdout())

setClass("A", representation(x="numeric"))
setMethod("initialize", "A",
          function(.Object, ...) cat("Shouldn't be here\n"))

cleanEx(); ..nameEx <- "eg2"

### * eg2

flush(stderr()); flush(stdout())

setClass("A", representation(x="numeric"))
a <- new("A")



[Rd] R CMD check does not remove all S4 methods defined in examples
Martin Morgan