Message-ID: <BAY17-F39B71F923DC9F62EEFA2E1D1230@phx.gbl>
Date: 2005-04-28T02:29:21Z
From: Ali -
Subject: Defining binary indexing operators
In-Reply-To: <971536df0504271807598e697d@mail.gmail.com>
> > >
> > > 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?