Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to define generics in an R package

Tags:

r

r-s4

I want to write a package using S4 objects and need to register new generic functions. I want to split my code into several files - each class gets its own .R file. However their methods share of course common generic functions. Where do I need to call setGeneric() such that I can use setMethod() in any .R file of the package? Currently I get an error of the type

Error in setMethod("XXX", signature(yyy = "YYY"), definition = function(yyy,  : 
  no existing definition for function 'XXX'
like image 829
Jack Avatar asked Sep 11 '25 14:09

Jack


1 Answers

Organize your code however you see fit (e.g., an AllGenerics.R file, or a XXX-methods.R file that starts with the generic). Use the 'Collate:' field in the DESCRIPTION file to ensure that the generics are available before methods defined.

like image 172
Martin Morgan Avatar answered Sep 13 '25 04:09

Martin Morgan