s-news
[Top] [All Lists]

Loops to create "what" for rm(list=what)

To: "S-plus list (S-plus list)" <s-news@wubios.wustl.edu>
Subject: Loops to create "what" for rm(list=what)
From: "P.J.Wells" <P.J.Wells@open.ac.uk>
Date: Thu, 24 Apr 2003 12:48:12 +0100
I create some objects using the following script:

for (i in 1:length(A.list))
        for (j in 1:length(B.list))
                assign(paste(A.list[i], ".foo.", B.list[j], ".bar", sep=""),
                        foobar(A.list[i], some.arg=B.list[j]))

[where A.list <- c("a1", "a2", ... , "ai"), B.list <- c("b1", "b2", ... ,
"bj"), and foobar() takes the corresponding character arguments]

and save the results to my disk using dump.data() in a similar construction.

The real A.list has length=12 and there are five possible B.lists, some with
length>=300, and the resulting objects may be 100kb in size.

Thus I want to remove each set of objects from my S+ database before
creating the next lot, using something like:

object.names <- vector(length=length(B.list))
for (i in 1:length(A.list))
        for (j in 1:length(B.list)){
                        assign(object.names[j], paste(A.list[i], ".foo.",
B.list[j], ".bar", sep=""))
                        rm(list=object.names)
                }

But this gives (for length(A.list)=length(B.list)=3) 18 copies of the
following message

Warning messages:
  Warning in remove(list): "FALSE" to be removed not in database

> traceback()
Message: Error in parse(text = txt): Syntax error: Unbalanced parentheses,
expected ")", before "}" at this point:
script.run(exprs.literal={
object.names <- vector(length=length ...
        [j], ".bar", sep=""));   rm(list=object.names);  }; }

}
 
1: 

Considerable experimentation has so far merely produced a variety of results
for traceback().

I'd be very grateful if someone would point out my error, and if possible
supply a working solution.

Julian Wells

School of Management
The Open University
Walton Hall
Milton Keynes
MK7 6AA
United Kingdom

(01908) 654658
+44 (1908) 654658 


<Prev in Thread] Current Thread [Next in Thread>
  • Loops to create "what" for rm(list=what), P.J.Wells <=