Re: [R] Defining binary indexing operators

From: Ali - <saveez_at_hotmail.com>
Date: Thu 28 Apr 2005 - 12:29:21 EST

> > >
> > > Here is an example. Note that $ does not evaluate y so you have
> > >to do it yourself:
> > >
> > >x <- structure(3, class = "myclass")
> > >y <- 5
> > >foo <- function(x,y) x+y
> > >"$.myclass" <- function(x, i) { i <- eval.parent(parse(text=i)); foo(x,
> > i)
> > >}
> > >x$y # structure(8, class = "myclass")
> >

If I got it right, in the above example you provided '$' is defined as a method for a S3 class. How is it possible to do the same with a S4 class. If this is not possible, what is the best way to define the '$' operator whose first arguments is a S4 object and doesn't overwrite the global definition?



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Apr 28 12:33:33 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:27 EST