[R] overloading + operator for chars

2011-11-02 Thread Albert-Jan Roskam
Hello,   I would like to overload the + operator so that it can be used to concatenate two strings, e.g John + Doe = JohnDoe. How can I 'unseal' the + method? setMethod(+, signature(e1=character, e2=character), function(e1, e2) paste(e1, e2, sep=) ) Error in setMethod(+, signature(e1 =

Re: [R] overloading + operator for chars

2011-11-02 Thread Martin Morgan
On 11/02/2011 06:52 AM, Albert-Jan Roskam wrote: Hello, I would like to overload the + operator so that it can be used to concatenate two strings, e.g John + Doe = JohnDoe. How can I 'unseal' the + method? setMethod(+, signature(e1=character, e2=character), function(e1, e2) paste(e1, e2,

[R] overloading [ and [- using S3 classes

2010-10-30 Thread Mark Heckmann
How can I overload the [ and [- operators using S3 classes? Something like '['.{class} did not work or at least I do not know how to define it properly. For S4 it is straightforward: setMethod([, signature(x = myClass, i = numeric), function (x, i, j, ..., drop){ ...

Re: [R] overloading [ and [- using S3 classes

2010-10-30 Thread Gabor Grothendieck
On Sat, Oct 30, 2010 at 9:03 AM, Mark Heckmann mark.heckm...@gmx.de wrote: How can I overload the [ and [- operators using S3 classes? Something like '['.{class} did not work or at least I do not know how to define it properly. For S4 it is straightforward: setMethod([, signature(x =

[R] overloading the generic primitive functions + and [

2010-10-28 Thread Mark Heckmann
How can I add a new method to the generic function [ or + I want to create a S3 and S4 class that will use the [ and + method in a different way. How can I overload the generic primitive [ or + so the method dispatch will work correctly for my class? I saw an example of this in the ggplot2

Re: [R] overloading the generic primitive functions + and [

2010-10-28 Thread Barry Rowlingson
On Thu, Oct 28, 2010 at 9:31 AM, Mark Heckmann mark.heckm...@gmx.de wrote: How can I add a new method to the generic function [ or + I want to create a S3 and S4 class that will use the [ and + method in a different way. How can I overload the generic primitive [ or + so the method dispatch

Re: [R] overloading the generic primitive functions + and [

2010-10-28 Thread Christofer Bogaso
Dear Barry, this is really interesting. However I could not understand this line: Ops.ss=function(e1,e2){paste(e1,e2)} Where you have told R to behave + function differently when it faces ss class? What should be the ideal approach if I what to use * function? Thanks, On Thu, Oct 28, 2010 at

Re: [R] overloading the generic primitive functions + and [

2010-10-28 Thread Martin Morgan
On 10/28/2010 02:17 AM, Barry Rowlingson wrote: On Thu, Oct 28, 2010 at 9:31 AM, Mark Heckmann mark.heckm...@gmx.de wrote: How can I add a new method to the generic function [ or + I want to create a S3 and S4 class that will use the [ and + method in a different way. How can I overload

Re: [R] overloading the generic primitive functions + and [

2010-10-28 Thread Barry Rowlingson
On Thu, Oct 28, 2010 at 2:12 PM, Martin Morgan mtmor...@fhcrc.org wrote: Not so hard, eh? Though then like your S3 implementation this makes all 'Ops' (see ?Ops) Except you have to re-run the set* things every R session: setClass(SS, character) setMethod(Ops, c(SS, SS), function(e1, e2)

Re: [R] overloading the generic primitive functions + and [

2010-10-28 Thread Barry Rowlingson
On Thu, Oct 28, 2010 at 12:14 PM, Christofer Bogaso bogaso.christo...@gmail.com wrote: Dear Barry, this is really interesting. However I could not understand this line: Ops.ss=function(e1,e2){paste(e1,e2)} Where you have told R to behave + function differently when it faces ss class? What

Re: [R] overloading the generic primitive functions + and [

2010-10-28 Thread Hadley Wickham
Note how S3 methods are dispatched only by reference to the first argument (on the left of the operator). I think S4 beats this by having signatures that can dispatch depending on both arguments. That's somewhat of a simplification for primitive binary operators. R actually looks up the method

[R] overloading base function

2009-10-19 Thread David van Leeuwen
Hello, I am trying to write an R package for doing analysis of speaker recognition systems. The big thing in this line of research is a DET-plot (detection Error Trade-off, a ROC plot with qnorm() warped axes). My approach has been to make a class det and also a function det() that will

Re: [R] overloading base function

2009-10-19 Thread Gabor Grothendieck
Perhaps you could just call it Det. On Mon, Oct 19, 2009 at 7:16 PM, David van Leeuwen david.vanleeu...@gmail.com wrote: Hello, I am trying to write an R package for doing analysis of speaker recognition systems.  The big thing in this line of research is a DET-plot (detection Error

Re: [R] Overloading some non-dispatched S3 methods for new classes

2009-05-10 Thread Gavin Simpson
On Sat, 2009-05-09 at 20:50 +0200, Carlos J. Gil Bellosta wrote: Hello, I am building a package that creates a new kind of object not unlike a dataframe. However, it is not an extension of a dataframe, as the data themselves reside elsewhere. It only contains metadata. I would like to be

[R] Overloading some non-dispatched S3 methods for new classes

2009-05-09 Thread Carlos J. Gil Bellosta
Hello, I am building a package that creates a new kind of object not unlike a dataframe. However, it is not an extension of a dataframe, as the data themselves reside elsewhere. It only contains metadata. I would like to be able to retrieve data from my objects such as the number of rows, the

Re: [R] Overloading in R

2009-02-15 Thread Martin Morgan
Hi Shrikanth -- SHRIKANTH SHANKAR shrikanth.shan...@gmail.com writes: I have been trying to write a new class that reimplements the vector class. As a test of my overloading I decided to try and and call t.test on two vectors which were objects of my class rather than the default class.

[R] Overloading in R

2009-02-14 Thread SHRIKANTH SHANKAR
I have been trying to write a new class that reimplements the vector class. As a test of my overloading I decided to try and and call t.test on two vectors which were objects of my class rather than the default class. The overloaded length I wrote seems to work correctly. I used

Re: [R] Overloading %*%

2008-03-17 Thread Martin Maechler
SpG == Spencer Graves [EMAIL PROTECTED] on Sun, 16 Mar 2008 19:47:29 -0700 writes: SpG Dear Martin: This is wonderful. Thank you very much. SpG It would be a great help if your suggestions SpG could be added to See Also and Examples for SpG methods. ?methods has had

[R] Overloading %*%

2008-03-16 Thread Joe Cainey
Hi, Is it possible to supply a new method for the %*% operator? I need to provide a new method for working on variables of a newly defined class, ad. I've had no problems overloading +, * etc.., using code such as: +.ad - function(a,b = NULL) { # further code here } I've tried to do the

Re: [R] Overloading %*%

2008-03-16 Thread knoblauch
Joe Cainey jcainey at gmail.com writes: Is it possible to supply a new method for the %*% operator? clipped I've tried to do the same thing with %*%: %*%.ad - function(a,b) { # further code here } However this doesn't work; the new method is never called and the standard %*%

Re: [R] Overloading %*%

2008-03-16 Thread Spencer Graves
Thanks, Ken. 1. How can I find S4 methods for a given function given class(es) of objects? The 'showMethods' function lists available generics for a given function; showMethods('%*%') just produced for me a list of 52 different signatures for %*%. However, I don't know how to find

Re: [R] Overloading %*%

2008-03-16 Thread Martin Morgan
Spencer Graves wrote: Thanks, Ken. 1. How can I find S4 methods for a given function given class(es) of objects? The 'showMethods' function lists available generics for a given function; showMethods('%*%') just produced for me a list of 52 different signatures for %*%.

Re: [R] Overloading %*%

2008-03-16 Thread Spencer Graves
Dear Martin: This is wonderful. Thank you very much. It would be a great help if your suggestions could be added to See Also and Examples for methods. Thanks again, Spencer Graves Martin Morgan wrote: Spencer Graves wrote: Thanks, Ken. 1. How can I