Skip to content

be careful: using attach in R functions

1 message · Liaw, Andy

#
You can write your code more defensively.  There are a few ways to do that:

1. Right after the attach(object), do on.exit(detach(object)).
2. If you know the function will be call repeatedly, it might be a good idea
to check whether the object has been attached.  This way you only need to
attach once.  I can think of a couple of way to do that. The simplest is
probably to check and see if the object name appear in the search list. 

Andy
------------------------------------------------------------------------------
Notice:  This e-mail message, together with any attachments,...{{dropped}}