[R] Generic Functions

From: Dominik Locher <dominik.locher_at_bondsearch.ch>
Date: Sun, 24 Feb 2008 14:04:58 +0100


I have some problems in defining new generic functions and classes. Just have a look at the following example:




#I would like to define a specific function for class PROBECLASS with other
arguments than for the generic function "setType" of fPortfolio. setGeneric("setType<-", function(object, value) standardGeneric("setType<-"))


Fehler in makeGeneric(name, fdef, fdeflt, group = group, valueClass = valueClass, :
  the formal arguments of the generic function for "setType<-" (object, value) differ from those of the non-generic to be used as the default (spec, value)

setReplaceMethod("setType", "PROBECLASS", function(object, value){

  object_at_type <- value   object



obj = new("PROBECLASS")
setType(obj) = "test"


If I don't require fPortfolio it works fine. However, is it not possible to create two generic functions with the same name but different arguments? setType for fPortfolio may be differ completely from setType of
What's the best way to have functions which belongs to an object of a specific class? I had a look at the paper "S4 Classes in 15 pages, more or less" (feb12, 2003), however, I could not found what I did wrong...

Any help is highly appreciated.


R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sun 24 Feb 2008 - 13:12:31 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 24 Feb 2008 - 17:30:15 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive