[R] How do you save in R?

Wacek Kusnierczyk Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Mon May 18 11:48:26 CEST 2009


ronggui wrote:
> I would second Dieter's point.
>   

me to, among others because:

> 2009/5/18 Dieter Menne <dieter.menne at menne-biomed.de>:
>   
>> Patrick Burns <pburns <at> pburns.seanet.com> writes:
>>
>>     
>>> I disagree with Dieter's last point.
>>> Whether you use 'attach' or 'load'
>>> should depend on whether you want the
>>> objects in the file to remain separate
>>> ('attach') or mixed into the global
>>> environment ('load').
>>>       
>> Technically a good point, but I found it helpful for starters who want to
>> avoid the inferno of "what's attached now?" not to use it at all.
>> My suggestion is to use with() instead because it has a higher locality.
>>
>>     

i've seen code where an assumption is made to the effect that packages
attached inside a function call will be automatically detached, e.g.:

    search()
    (function() attach(list()))()
    search()

unfortunately, ?attach falls short of explaining this is an incorrect
expectation, and it might be a good idea to do so. 

attach may also be confusing in how it interferes with lexical scoping:

    p = function() print(c)
    l = list(c=0)
   
    attach(l)
    p()
    detach()

    with(l, p())

i.e., attach may modify the behaviour of functions without changing
what's passed to them as arguments.

vQ




More information about the R-help mailing list