From sfalcon at fhcrc.org  Tue May  8 06:59:57 2007
From: sfalcon at fhcrc.org (Seth Falcon)
Date: Mon, 07 May 2007 21:59:57 -0700
Subject: [Rd] Problem calling $ inside a $ method
Message-ID: <m24pmn6hbm.fsf@ziti.local>

Hello,

I wonder if this will make it through the spam filters given the
subject line.

I'm seeing the following when trying to call a dollar method inside of
a dollar method.


    setClass("Foo", representation(d="list"))
    [1] "Foo"

    f <- new("Foo", d=list(bob=1, alice=2))

## We can call dollar at this level and it works as expected

    `$`(f, "bo")
    [1] 1

    `$`(f, "al")
    [1] 2

## So set a method on Foo that does this

    setMethod("$", "Foo", function(x, name) `$`(x at d, name))
    [1] "$"

## But it doesn't work.  Why?

    f$bo
    NULL

    f$al
    NULL

## Here is a hackish workaround.

    setMethod("$", "Foo", function(x, name)
              eval(substitute(x at d$FOO, list(FOO=name))))
    [1] "$"

    f$bo
    [1] 1

    f$al
    [1] 2

Other suggestions for workarounds?  Is this a bug?

+ seth

-- 
Seth Falcon | Computational Biology | Fred Hutchinson Cancer Research Center
http://bioconductor.org



[Rd] Problem calling $ inside a $ method
Seth Falcon