On 4/27/05, Ali - <[EMAIL PROTECTED]> wrote:
>
>
> > > >
> > > > 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 <-
> >
> > 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 = "myclas
On 4/27/05, Ali - <[EMAIL PROTECTED]> wrote:
>
>
>
> > >
> > > Assume we have a function like:
> > >
> > > foo <- function(x, y)
> > >
> > > how is it possible to define a binary indexing operator, denoted by $,
> >so
> > > that
> > >
> > > x$y
> > >
> > > functions the same as
> > >
> > > foo(
Excuse me! I misunderstood the question, and indeed, it is necessary be
that complicated when you try to make x$y behave the same as foo(x,y),
rather than foo(x,"y") (doing the former would be inadvisible, as I
think someelse pointed out too.)
Tony Plate wrote:
It's not necessary to be that co
>
> Assume we have a function like:
>
> foo <- function(x, y)
>
> how is it possible to define a binary indexing operator, denoted by $,
so
> that
>
> x$y
>
> functions the same as
>
> foo(x, y)
Here is an example. Note that $ does not evaluate y so you have
to do it yourself:
x <- structure(3
It's not necessary to be that complicated, is it? AFAIK, the '$'
operator is treated specially by the parser so that its RHS is treated
as a string, not a variable name. Hence, a method for "$" can just take
the indexing argument directly as given -- no need for any fancy
language tricks (eva
On 4/27/05, Ali - <[EMAIL PROTECTED]> wrote:
>
> Assume we have a function like:
>
> foo <- function(x, y)
>
> how is it possible to define a binary indexing operator, denoted by $, so
> that
>
> x$y
>
> functions the same as
>
> foo(x, y)
Here is an example. Note that $ does not evaluate
[mailto:[EMAIL PROTECTED] On Behalf Of Huntsinger, Reid
Sent: Wednesday, April 27, 2005 4:10 PM
To: 'Ali -'; r-help@stat.math.ethz.ch
Subject: RE: [R] Defining binary indexing operators
That sounds like a recipe for headaches. If you want to use "x$y" because
you want a certain kin
. That way you won't break existing code.
Reid Huntsinger
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Ali -
Sent: Wednesday, April 27, 2005 3:11 PM
To: r-help@stat.math.ethz.ch
Subject: [R] Defining binary indexing operators
Assume we have a fun
Assume we have a function like:
foo <- function(x, y)
how is it possible to define a binary indexing operator, denoted by $, so
that
x$y
functions the same as
foo(x, y)
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-hel
10 matches
Mail list logo