[R] be careful: using attach in R functions

Thomas Petzoldt thpe at hhbio.wasser.tu-dresden.de
Tue Feb 24 20:47:47 CET 2004


li dongfeng wrote:
> Hi there,
> 
>   I have just found that the ``attach'' function
> can get you into trouble when called many times.
[..]
>   Below is a demonstration of this performance loss,
> you will see a linear growth in CPU time usage.
> Adding a ``detach()'' call at the end of ``f''
> will get rid of this problem.

Yes, this behaviour is well known (to me using attach for differential
equation models long ago). Detaching ist absolutely required. As an
alternative one can use the with() function.

Thomas P.




More information about the R-help mailing list