[R] clear R-objects inside a function?

Paul E Johnson pauljohn at ukans.edu
Tue Apr 10 16:08:18 CEST 2001

Using RedHat Linux 7.0, R-1.2.2, R-hdf5-1.2 library, 

I want to load a dataset, do some stuff with it, then erase its objects,
get an other, repeat.  My friend wrote a function which tried to clear
away all the objects. At the end, it uses rm() to remove objects. This
is the same way we do it interactively, from the R prompt:

testLoadSeveralHDF <- function(numFiles) {
  for (i in 0:(numFiles-1)) {
    filename <- paste("trial",i,".hdf",sep="")
    rm(list = ls(pat="g*"))   

However, after that program runs, the g* objects are not erased, but
typing "rm(list=ls(pat="g*")) from the command line does erase them.  I
realized there's something about the environment that I need to tell the
function, I just don't know what?


ps. Now that Frank Harrell is using R, I'm so enthusiastic! I'll do some
R in my advanced methods class in Fall, 2001 and continue my updating of
the tipsheet: http://lark.cc.ukans.edu/~pauljohn/R/statsRus.html

Paul E. Johnson                       email: pauljohn at ukans.edu
Dept. of Political Science            http://lark.cc.ukans.edu/~pauljohn
University of Kansas                  Office: (785) 864-9086
Lawrence, Kansas 66045                FAX: (785) 864-5700
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list