s-news
[Top] [All Lists]

Re: Error: Too many databases in use?

To: "Sarah Henderson" <sarah.henderson@ubc.ca>, <s-news@lists.biostat.wustl.edu>
Subject: Re: Error: Too many databases in use?
From: "Michael Camilleri" <MichaelCamilleri@branz.co.nz>
Date: Mon, 30 Apr 2007 10:40:55 +1200
In-reply-to: <7.0.1.0.2.20070429002756.02508bc8@ubc.ca>
References: <7.0.1.0.2.20070429002756.02508bc8@ubc.ca>
Thread-index: AceKr3MiW5wlhf9XSzmjp8zi2HBDfw==
Thread-topic: Error: Too many databases in use?
I think what is happening is that when you use get() on an object it
temporarily attaches that object as a database. That connection only
gets broken when either the function call ends (in this case lapply), or
the S+ session ends. Basically with the way you have coded it you are
attaching DATA.FRAME every time you call get and not detaching it,
leading to ballooning databases.

You could try calling synchronize in PAIRWISE, and that might sort
things out. You could also try to detach DATA.FRAME before exiting
PAIRWISE.

Several ways around it:

1) Attach DATA.FRAME before your call lapply then access it in the
function call as in:

attach(DATA.FRAME)
lapply(.....)
...

NAME1 <- paste("ONE", ID, sep="")
VECTOR1 <- get(NAME1)

Or attach DATA.FRAME explicitly in PAIRWISE, and detach it explicitly
before exiting PAIRWISE. This should stop the databases ballooning.
PAIRWISE(...)
...
        attach(DATA.FRAME)
        NAME1 <- paste("ONE", ID, sep="")
        VECTOR1 <- get(NAME1)
        NAME2 etc
        detach(DATA.FRAME)

2) You could just access the object directly as in

NAME1 <- paste("ONE", ID, sep="")
VECTOR1 <- DATA.FRAME[NAME1]

3) Pass DATA.FRAME as an argument to PAIRWISE and access it in the
function.

My preference is 3) as that is good programming practice. S+ is quite
happy to pass very large objects into functions.

In my experience attaching data frames is not intended for heavy duty
data processing. It is really intended as a convenience when you are
doing small or interactive analyses so that you can deal directly with a
limited set of variable names as objects, rather than having to
continually refer to the full data frame.

Michael

MICHAEL CAMILLERI BSc, MSc, PhD 
BUILDING PHYSICIST      
T +64 4 237 1170
DDI +64 4 237 1174
PRIVATE BAG 50908       
PORIRUA CITY 5240       
WWW.BRANZ.CO.NZ 

<Prev in Thread] Current Thread [Next in Thread>