Re: [R-SIG-Mac] Problems with definitions of S4-generics

2006-12-21 Thread Simon Urbanek
Joerg,

this appears to have nothing to do with the Mac port, so please use  
the appropriate mailing list - R-help or R-devel. Also you should try  
to boil it down to a reproducible example -  sourcing local files  
doesn't help.

Cheers,
Simon

On Dec 21, 2006, at 2:37 PM, Jörg Beyer wrote:

 I installed R 2.4.1 yesterday (coming from 2.2.1), and made an  
 interesting
 observation today, which may be a simple coincidence, or related to  
 R 2.4.1.
 [...]
 The code itself has worked without problems with R 2.2.1 -- the  
 code is not
 the problem.

FWIW: That is a very strong assertion - just because some code worked  
previously doesn't mean that it correct or is supposed to work in a  
recent version.

___
R-SIG-Mac mailing list
R-SIG-Mac@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-mac


Re: [R-SIG-Mac] Problems with definitions of S4-generics

2006-12-21 Thread Byron Ellis
This isn't a Mac problem, this is a moving from 2.2 to 2.4. You'll
probably get better answers on R-devel. My guess would be that a cache
used by methods to store frequently used generics isn't getting
flushed by removeGeneric properly, though a brief glance at the code
suggests that it tries. Your best bet is probably to file a bug report
with a simple example.

On 12/21/06, Jörg Beyer [EMAIL PROTECTED] wrote:
 Hello all,

 I installed R 2.4.1 yesterday (coming from 2.2.1), and made an interesting
 observation today, which may be a simple coincidence, or related to R 2.4.1.

 Platform:
 Mac G4/400 PCI (Oct. 1999, 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


 Problem-intro:
 The file /Volumes/RAMdisk/beyerjoerg/Scripting R/source-0.R contains code
 that constructs and registers a S4-style generic function, *but only if the
 function does not exist, to avoid unnecessary computations.*
 This is the stub to test whether or not a S4-Generic is present:
   if ( ! isGeneric( nameOfS4generic )) {
 setGeneric ...
   }

 The code itself has worked without problems with R 2.2.1 -- the code is not
 the problem.
 Okay, let's start. The function in this example is cleanDataset; to
 demonstrate the problem, I'm using a second S4-generic here, it is named
 removeFactors.


  Fist the correct part
 ## Source the code and build the S4-generic
  source( /Volumes/RAMdisk/beyerjoerg/Scripting R/source-0.R )


 ## Do some tests to see if the generic is present,
 ## and have a look at some details
  isGeneric( cleanDataset )
 [1] TRUE


  findFunction( cleanDataset )
 [[1]]
 environment: R_GlobalEnv


  cleanDataset
 nonstandardGenericFunction for cleanDataset defined from package
 .GlobalEnv

 function (object)
 {
 standardGeneric(cleanDataset)
 }
 environment: 0x293bbb8
 Methods may be defined for arguments: object


  getGeneric( cleanDataset )
 ## same result as above



  Now what I suspect is a bug
 ## Delete the S4-generic (and all its methods, if any)
 ## and repeat the forensic test calls
  removeGeneric( cleanDataset )
 [1] TRUE


 # The following is as expected...
 ## [I'm trying here to re-translate the message from German back
 ## to English, so please don't be irritated if there are any differences]
  cleanDataset
 Error: object cleanDataset not found


 # Oops, but what's that?
  getGeneric( cleanDataset )
 nonstandardGenericFunction for cleanDataset defined from package
 .GlobalEnv

 function (object)
 {
 standardGeneric(cleanDataset)
 }
 environment: 0x19be228
 Methods may be defined for arguments: object


 ## Why not try to remove it a second time?
  removeGeneric( cleanDataset )
 [1] FALSE
 Warning message:
 generic function cleanDataset not found for removal in:
 removeGeneric(cleanDataset)


 # Another test to see if there is a function definition somewhere
 # Weird ...
  isGeneric( cleanDataset )
 [1] TRUE


 # Okay, let's see, where it is
 # Ah, registered, but nowhere ...
  findFunction( cleanDatasets )
 list()


 # Just to be sure, test another generic (which I know is *present
 # and working*)   Okay, as expected...
  findFunction( removeFactors )
 [[1]]
 environment: R_GlobalEnv




  Consequence:
 # Because my code first tests whether a generic is present or not
 # (see above), re-sourcing the definition code leads to nothing
  source( /Volumes/RAMdisk/beyerjoerg/Scripting R/source-0.R )
  cleanDataset
 Error: object cleanDataset not found



 When I skip testing the existence of a generic, everything works as
 expected, of course.
 Deleting and redefining generic functions this way never caused problems
 under R 2.2.1 (I'm developing with this code since six months, the helper
 functions have been called over and over again), but I don't have explicit
 results for the above tests and R 2.2.1.

 Running the above test case in R.app or from the terminal makes no
 difference. At the moment, I can't see a reason why R should do what it
 obviously does here, but I may have misunderstood something essential.

 Some comments may be helpful.
 Thanks for your interest.

 Cheers

 Jörg

 ___
 R-SIG-Mac mailing list
 R-SIG-Mac@stat.math.ethz.ch
 https://stat.ethz.ch/mailman/listinfo/r-sig-mac



-- 
Byron Ellis ([EMAIL PROTECTED])
Oook -- The Librarian

___
R-SIG-Mac mailing list
R-SIG-Mac@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-mac