[R] as.character methods
Prof Brian Ripley
ripley at stats.ox.ac.uk
Thu Jan 13 23:58:18 CET 2005
You seem to be confusing `generic' with `S4 generic', and `method' with
`S4 method'.
Note that all references to `generic' and `method' outside the `methods'
package are not to S4 concepts unless explicitly stated.
On Thu, 13 Jan 2005, McGehee, Robert wrote:
> Hello,
> ?as.character says that the as.character function is a generic with
> usage: as.character(x, ...). So, I want to create an S4 object with an
> as.character method following the above usage, but I get the below error
> telling me that ... isn't in the generic for as.character.
>
>> setClass("tmp", "numeric")
>> setMethod("as.character", "tmp", function(x, ...) paste(x, c(...)))
> Error in rematchDefinition(definition, fdef, mnames, fnames, signature)
> :
> Methods can add arguments to the generic only if "..." is an
> argument to the generic
>
> Am I reading the documentation incorrectly? How do I correctly pass the
> ... object to the method for this "tmp" object?
>
> However I note that looking at the generic function, I see no mention of
> ... (despite the documentation).
>> getGeneric("as.character")
> standardGeneric for "as.character" defined from package "base"
>
> function (x)
> standardGeneric("as.character", .Primitive("as.character"))
> <environment: 0145EDC4>
> Methods may be defined for arguments: x
>
>
> So, briefly, is the documentation wrong? Am I doing something wrong? Can
> I create an as.character method and pass additional arguments to it as I
> think I should be able to?
Briefly, No, yes, yes.
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list