On Fri, 25 Feb 2005, Henrik Bengtsson wrote:

.Primitive() does not necessarily apply non-S3 generic function, cf.
as.character().

You mean `imply'? In fact "+" *is* S3 generic and has methods defined:

methods("+")
[1] +.Date   +.POSIXt

It is also group-generic, part of the Ops group with many more methods via that route. See ?Ops.

An options is to do

"+" <- function(...) UseMethod("+")
"+.default" <- .Primitive("+")
"+.character" <- function(...) paste(...,sep="")

"abc" + "def" + "ghi"

# [1] "abcdefghi"

[Re-defining R basics is seriously not recommended.]

The question is if you want to do this. The "+" is probably non-generic for
a purpose. One may be that having a generic function for such a basic method
will most likely slow down many methods substantially.

Well, it is generic. The issue is that only coercion between numeric (broad sense, including complex) types is supported for the arithmetical operators, presumably to avoid the ambiguity of things like


x <- 123.45
y <- as.character(1)
x + y

Should that be 124.45 or "123.451"? One of the difficulties of any dispatch on two arguments is how to do the best matching on two classes, especially with symmetric operators like "+". Internally R favours simple fast rules.


-- Brian D. Ripley, [EMAIL PROTECTED] 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

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to