R-beta: dataframes and function side effects

Martyn Plummer plummer at iarc.fr
Tue Feb 17 15:31:52 CET 1998


Jim Lindsey wrote:
> 
> I have a function that returns a dataframe. A second funtion calls the
> first to obtain the dataframe, then attaches it to have access to the
> column names. Lo and behold, this is done globally so that, after
> running the second function a few times, I have all kinds of
> dataframes attached giving all sorts of weird errors. If I put a
> detach at the end of the second function, things are better, but
> during debugging, if I ctrl-C while it is running (this is a random
> effects Cox PH model, rather slow), I start accumulating dataframes
> again. I suppose that if (some version of) S-Plus does the same thing,
> this must be good stuff but it is a very annoying side effect of a
> function to have dataframes attached globally and not locally.

S-PLUS 3.3 does do the same thing. If you want to safely detach
the data frame even when you inturrupt your function, you could
put 
	on.exit(if(search()[2]=="your.data.frame") detach())

at the beginning of your function.

Martyn
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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