From mtmorgan at fhcrc.org  Thu Oct  7 04:21:35 2010
From: mtmorgan at fhcrc.org (Martin Morgan)
Date: Wed, 06 Oct 2010 19:21:35 -0700
Subject: [Rd] Recursion error after upgrade to
	R_2.11.1	[Sec=Unclassified]
In-Reply-To: <42C7503E0B99F248B06BC65E7D2B4E020187DD7258BC@EX2K7-CCR.AAD.GOV.AU>
References: <42C7503E0B99F248B06BC65E7D2B4E020187DD7258BC@EX2K7-CCR.AAD.GOV.AU>
Message-ID: <4CAD2EAF.8040505@fhcrc.org>

On 10/06/2010 06:12 PM, Troy Robertson wrote:
> Hi all,
> 
> After no replies to my previous message I thought I might show some code to demonstrate the change and again seek any explanation for the error now thrown by my code after upgrading from 2.10.1 to 2.11.1.
> 
> Thanks
> Troy
> --------------------------------------------------------
> setClass("PortableObject",
>         representation(test1    = "character"),
> 
>         prototype(      test1   = ""),
>           contains = ".environment"
> )
> 
> setMethod("initialize", "PortableObject",
>     function(.Object, ..., .xData=new.env(parent=emptyenv())) {
>                 .Object <- callNextMethod(.Object, ..., .xData=.xData)
> 
>                 .Object at test1 <- "Foo"
>                 # Following line works under 2.10.1 but now throws
>                 # Error: evaluation nested too deeply: infinite recursion / options(expressions=)?
>                 #####.Object[["test2"]] <- "Bar"
>                 # The following does what I want though
>                 .Object$test3 <- "Baa"
> 
>                 return(.Object)
>         }
> )
> 
> e <- new("PortableObject")

The explicit example does help -- it's clear what bug you are
encountering. Here's the code in R-2.10

> selectMethod("[[<-", ".environment")
Method Definition:

function (x, i, j, ..., value)
{
    call <- sys.call()
    call[[2]] <- x at .Data
    eval.parent(call)
    x
}


and 2.11.1

> selectMethod("[[<-", ".environment")
Method Definition:

function (x, i, j, ..., value)
{
    .local <- function (x, i, j, ..., exact = TRUE, value)
    {
        call <- sys.call()
        call[[2]] <- x at .Data
        eval.parent(call)
        x
    }
    .local(x, i, j, ..., value = value)
}

Apparently the 'exact' argument has been added, and because the method
signature differs from the generic, a .local function is created. That
'sys.call()' originally returned the environment in which the generic
was called, but now it returns the environment in which .local is
defined. And so eval() keeps evaluating .local(). This I think is a bug.

For what it's worth, if I were interested in minimizing copying I would
set up initialize so that it ended with callNextMethod(<...>), on the
hopes that the method eventually called would take care not to make too
many copies on slot assignment.

Martin

> 
> alterEGo <- function(o = "EPOCObject") {
>         o at test1 <- "Boo"
> 
>         # Following line works under 2.10.1 but now throws
>         # Error: evaluation nested too deeply: infinite recursion / options(expressions=)?
>         ####o[["test2"]] <- "Who"
>         # The following does what I want though
>         o$test3 <- "Hoo"
> 
>         # NOTE: No return
> }
> 
> alterEGo(e)
> e at test1
> e$test2
> e[["test3"]]
> e at .xData[["test3"]]
> ___________________________________________________________________________
> 
>     Australian Antarctic Division - Commonwealth of Australia
> IMPORTANT: This transmission is intended for the addressee only. If you are not the
> intended recipient, you are notified that use or dissemination of this communication is
> strictly prohibited by Commonwealth law. If you have received this transmission in error,
> please notify the sender immediately by e-mail or by telephoning +61 3 6232 3209 and
> DELETE the message.
>         Visit our web site at http://www.antarctica.gov.au/
> ___________________________________________________________________________
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel


-- 
Computational Biology
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109

Location: M1-B861
Telephone: 206 667-2793



[Rd] Recursion error after upgrade to R_2.11.1 [Sec=Unclassified]
Martin Morgan