[R] as.character methods

McGehee, Robert Robert.McGehee at geodecapital.com
Thu Jan 13 22:47:12 CET 2005


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?

Thanks,
Robert

Robert McGehee
Geode Capital Management, LLC
53 State Street, 5th Floor | Boston, MA | 02109
Tel: 617/392-8396    Fax:617/476-6389
mailto:robert.mcgehee at geodecapital.com



This e-mail, and any attachments hereto, are intended for use by the
addressee(s) only and may contain information that is (i) confidential
information of Geode Capital Management, LLC and/or its affiliates,
and/or (ii) proprietary information of Geode Capital Management, LLC
and/or its affiliates. If you are not the intended recipient of this
e-mail, or if you have otherwise received this e-mail in error, please
immediately notify me by telephone (you may call collect), or by e-mail,
and please permanently delete the original, any print outs and any
copies of the foregoing. Any dissemination, distribution or copying of
this e-mail is strictly prohibited.




More information about the R-help mailing list