[Rd] formal argument "envir" matched by multiple actual arguments

From: Hervé Pagès <hpages_at_fhcrc.org>
Date: Mon, 01 Jun 2009 18:42:52 -0700


Hi list,

This looks similar to the problem reported here

   https://stat.ethz.ch/pipermail/r-devel/2006-April/037199.html by Henrik Bengtsson a long time ago. It is very sporadic and non-reproducible.
Henrik, do you remember if your code was using reg.finalizer()? I tend to suspect it but I'm not sure.

I've been hunting this bug for months but today, and we the help of other Bioconductor users, I was able to isolate it and to write some code that seems to "almost" reproduce it (i.e. not systematically but most of the times).

(Just to put some context to the code below: it's a simplified version of some more complex code that we use in Bioconductor to manage memory caching of some big objects stored on disk. The idea is that objects of class A can be named. All A objects with the same name form a group. The code below implements a simple mechanism to trigger some action when a group is completely removed from memory i.e. when the last object in a group is garbage collected.)

   setClassUnion("environmentORNULL", c("environment", "NULL"))

   setClass("A",

     representation(
       aa="integer",
       groupname="character",
       groupanchor="environmentORNULL"
     )

   )

.A.group.sizes <- new.env(hash=TRUE, parent=emptyenv())

.inc.A.group.size <- function(groupname)
   {

     group.size <- 1L
     if (exists(groupname, envir=.A.group.sizes, inherits=FALSE))
         group.size <- group.size +
                       get(groupname, envir=.A.group.sizes, inherits=FALSE)
     assign(groupname, group.size, envir=.A.group.sizes, inherits=FALSE)
   }

.dec.A.group.size <- function(groupname)
   {

     group.size <- get(groupname, envir=.A.group.sizes, inherits=FALSE) - 1L
     assign(groupname, group.size, envir=.A.group.sizes, inherits=FALSE)
     return(group.size)

   }

   newA <- function(groupname="")
   {

     a <- new("A", groupname=groupname)
     if (!identical(groupname, "")) {
         .inc.A.group.size(groupname)
         groupanchor <- new.env(parent=emptyenv())
         reg.finalizer(groupanchor,
                       function(e)
                       {
                           group.size <- .dec.A.group.size(groupname)
                           if (group.size == 0L) {
                               cat("no more object of group",
                                   groupname, "in memory\n")
                               # take some action
                           }
                       }
         )
         a_at_groupanchor <- groupanchor
     }
     return(a)

   }

The following commands seem to trigger the problem:

   > for (i in 1:2000) {a1 <- newA("group1")}
   > as.list(.A.group.sizes)
   > gc()
   > as.list(.A.group.sizes)
   > for (i in 1:2000) {a2 <- newA("group2")}
   Error in assign(".Method", method, envir = envir) :
     formal argument "envir" matched by multiple actual arguments

If it doesn't, then adding more rounds should finally do it:

   gc()
   for (i in 1:2000) {a3 <- newA("group3")}    gc()
   for (i in 1:2000) {a4 <- newA("group4")}

   etc...

Thanks in advance for any help with this!

H.

 > sessionInfo()
R version 2.9.0 (2009-04-17)
x86_64-unknown-linux-gnu

locale:
LC_CTYPE=en_CA.UTF-8;LC_NUMERIC=C;LC_TIME=en_CA.UTF-8;LC_COLLATE=en_CA.UTF-8;LC_MONETARY=C;LC_MESSAGES=en_CA.UTF-8;LC_PAPER=en_CA.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_CA.UTF-8;LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics grDevices utils datasets methods base

-- 
Hervé Pagès

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M2-B876
P.O. Box 19024
Seattle, WA 98109-1024

E-mail: hpages_at_fhcrc.org
Phone:  (206) 667-5791
Fax:    (206) 667-1319

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Tue 02 Jun 2009 - 01:46:59 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 02 Jun 2009 - 10:35:08 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive