From Beyerj at students.uni-marburg.de  Wed Jan 31 16:02:21 2007
From: Beyerj at students.uni-marburg.de (J=?ISO-8859-1?B?9g==?=rg Beyer)
Date: Wed, 31 Jan 2007 16:02:21 +0100
Subject: [Rd] Problems with definitions of S4-generics
Message-ID: <C1E66E0D.2458%Beyerj@students.uni-marburg.de>

Hello all, 

I'd like to report a problem related to S4 classes.

Platform: 
Mac G4/400 PCI (PPC-architecture)
Mac OS 10.4.8
R 2.4.1 for Mac OS X (CRAN binary, 2006-12-19) w/ R.app 1.18

Last December, Simon Urbanek confirmed that the issue is not platform
related, and that it is most likely a bug. He suggested to post my report
to "the appropriate mailing list" -- I choose r-devel.


#### Problem-intro:
## Define two S4-classes

setGeneric("foofunc", def=function(object) {standardGeneric("foofunc")})
setGeneric("barfunc", def=function(object) {standardGeneric("barfunc")})


#### Okay, let's start.
#### Fist the correct part
## Do some tests to see if the generic is present,
## and have a look at some details

isGeneric("foofunc")
# [1] TRUE


findFunction("foofunc")
# [[1]]
# <environment: R_GlobalEnv>


foofunc
# nonstandardGenericFunction for "foofunc" defined from package ".GlobalEnv"
# 
# function (object)
# {
#     standardGeneric("foofunc")
# }
# <environment: 0x293bbb8>
# Methods may be defined for arguments: object


getGeneric("foofunc")
# same result as above



#### Now what I suspect is a bug
## Delete the S4-generic and repeat the "forensic" test calls

removeGeneric("foofunc")
# [1] TRUE


## The following is as expected...

foofunc
# Fehler: objekt "foofunc" nicht gefunden [~ Error: object "foofunc" not
found]


## Oops, but what's that?

getGeneric("foofunc")
# nonstandardGenericFunction for "foofunc" defined from package ".GlobalEnv"
# 
# function (object)
# {
#     standardGeneric("foofunc")
# }
# <environment: 0x19be228>
# Methods may be defined for arguments: object


## Why not try to remove it a second time?

removeGeneric("foofunc")
# [1] FALSE
# Warning message:
# generic function "foofunc" not found for removal in:
removeGeneric("foofunc")


## Another test to see if there is a function definition somewhere
## Weird ... 

isGeneric("foofunc")
# [1] TRUE


## Okay, let's see, where it is
## Ah, registered, but nowhere ...

findFunction("foofunc")
# list()


## Just to be sure, test this other generic
## (which we know *is present*)
## Okay, as expected...

findFunction("barfunc")
# [[1]]
# <environment: R_GlobalEnv>


## End of demo



There are situations where this behavior has negative consequences.
Thanks for your interest.

Cheers

J?rg



[Rd] Problems with definitions of S4-generics
J=?ISO-8859-1?B?9g==?=rg Beyer