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
; <- function(...) UseMethod("||")
"||.default" <- .Primitive("||")
"||.character" <- function(...) paste(...,sep="")
"abc" || "def" || "ghi"
The "&" or "|" operators are nice but probably not
encer Graves [mailto:[EMAIL PROTECTED]
Sent: Thursday, February 24, 2005 3:46 PM
To: Gabor Grothendieck
Cc: r-help@stat.math.ethz.ch
Subject: Re: [R] string concatenation operator
Can we do something to make the following work:
> "+.character" <- function(x,y) paste(x,y,sep=&qu
I believe not, because:
> get("+")
.Primitive("+")
i.e., it's not an S3 generic.
Andy
> From: Spencer Graves
>
> Can we do something to make the following work:
>
> > "+.character" <- function(x,y) paste(x,y,sep="")
> > "abc"+"def"
> Error in "abc" + "def" : non-numeric argument to b
t be re-defined
FYI, your S3 method wouldn't work anyway as the arguments for the +
operator are e1, e2 not x, y.
-Original Message-
From: Spencer Graves [mailto:[EMAIL PROTECTED]
Sent: Thursday, February 24, 2005 3:46 PM
To: Gabor Grothendieck
Cc: r-help@stat.math.ethz.ch
Subject: Re: [R] st
Can we do something to make the following work:
> "+.character" <- function(x,y) paste(x,y,sep="")
> "abc"+"def"
Error in "abc" + "def" : non-numeric argument to binary operator
Thanks,
spencer graves
Gabor Grothendieck wrote:
Harris A. Jaffee jhmi.edu> writes:
: Why doesn't R hav
Harris A. Jaffee jhmi.edu> writes:
: Why doesn't R have one, like "." in Perl or juxtaposition in awk?
You could define one like this:
R> "%+%" <- function(x,y) paste(x,y,sep="")
R> "abc" %+% "def"
[1] "abcdef"
__
R-help@stat.math.ethz.ch mailing li
Why doesn't R have one, like "." in Perl or juxtaposition in awk?
It does not seem impossible to introduce one, if that would be
reasonable. It would seem to involve adding a table entry to
main/names.c for the binary operator and a corresponding internal
function, say do_dot(). This cannot be s