Hello,

I have the following problem when trying to use rm:

In a top level script file I have a loop iterating over some index. The loop
is not contained within a function, so the scope of variables declared in
the loop is global. Within this loop I generate several variables which
should be removed at the end of each iteration. To do this, I wrote a
function to clean up the workspace. An example is included here:

cleanUpWorkspace<-function()
{
    #Remove key data sructures, if they have been declared:
    delList<-list()
    for(varname in c("rv1","rv2", "rv3", "rv4")) {
        if(exists(varname)) {
            delList<-append(delList, varname)
        }
    }
    if(length(delList)>0) {
        rm(list=delList, pos=-1)
        #rm(list=delList, envir=parent.env(environment()))
        #rm(list=delList, envir=globalenv())
    }
}

Unfortunately, this fails to work - it aborts with the following error:
Error in rm(list = delList, pos = -1) : invalid first argument
if I use rm(list=delList, pos=-1)

Or with the following error:
Error in rm(list = delList, evir = parent.env(environment())) :
  ... must contain names or character strings
if I use rm(list=delList, envir=parent.env(environment())) or
rm(list=delList, envir=globalenv())

I get the same errors if I bypass rm entirely and use
.Internal(remove(delList, globalenv(),FALSE)).

I am using R version 2.10.0 running on a windows 7 box.

I want to declare the clean-up within a function for design purposes. The
full project is spread over several files and I am trying to keep the main
loop as simple as possible.

Sincerly,
Cormac Long.

	[[alternative HTML version deleted]]

