[R] loading .rda file

Jeff Newmiller jdnewmil at dcn.davis.ca.us
Tue Aug 30 20:03:40 CEST 2016


Thanks for the perspective, Martin. I personally feel like attaching to the search path is more confusing than being explicit, because it appears indistinguishable from namespace pollution yet for modifying data it creates copies in the current environment (in-place editing requires `<<-` which requires keeping your search path in mind as you work to know when to use it).
-- 
Sent from my phone. Please excuse my brevity.

On August 30, 2016 10:12:32 AM PDT, Martin Maechler <maechler at stat.math.ethz.ch> wrote:
>>>>>> Jeff Newmiller <jdnewmil at dcn.davis.ca.us>
>>>>>>     on Tue, 30 Aug 2016 09:36:05 -0700 writes:
>
>> You cannot. However, you can load the file into a dedicated
>environment to keep those names separated from your global environment.
>e.g. [1]
>
>yes, that's my "famous"  only-allowed use of  attach() :
>attach() an rda-file to your search patch instead of polluting
>your globalenv.
>
>  > The saveRDS / loadRDS 
>
>        saveRDS / readRDS   are the correct names
>
>> functions are an alternative handle one object at a time without
>dragging the object names into the picture (you have to name the
>re-loaded object).
>
>The fact that it is readRDS() and not loadRDS(),
>actually does convey via it is often "much better" in the sense
>of functional / transparent programming to use this pair in
>favor of save() / load() :
>readRDS() does *return* what we are interested in, and
>
>   result <- readRDS(<file>)
>
>is so much better than   load(<file>)   silently overwriting all
>kinds of objects in my globalenv.
>
>Indeed, I strongly advocate to use  saveRDS() and readRDS()
>much more frequently than they are used nowawadays.
>
>
>
>> However, the best approach is to write scripts that pull directly
>from your source (non-R) data files. This makes your work process
>reproducible as you develop it.
>
>Yes, but that's sometimes too inefficient.
>
>And then, some of us do simulations and other expensive
>computations, we need/want to save and re-read.
>
>and yes,  I *always*  use the equivalent of   q("no")  to leave R; 
>never save the workspace or load it at startup, unless
>accidentally on non-standard (for me) platforms.
>
>Martin
>
>    > [1] https://stat.ethz.ch/pipermail/r-help/2016-August/441078.html
>    > -- 
>    > Sent from my phone. Please excuse my brevity.
>
>> On August 30, 2016 7:37:24 AM PDT, Leslie Rutkowski
><leslie.rutkowski at gmail.com> wrote:
>    >> Hi,
>    >> 
>>> I'm slowly migrating from SAS to R and - for the very first time -
>I'm
>>> working with a native .Rda data file (rather than importing data
>from
>    >> other
>>> sources). When I load this .Rda file into the global environment
>using
>>> load("file path") I see a data.frame in the global environment
>called
>    >> "mydata" that corresponds to the .rda file.
>    >> 
>>> My question: how can I change the name of this data.frame to
>something
>    >> of
>    >> my choosing?
>    >> 
>    >> Thanks for considering this very simple question.
>    >> 
>    >> Leslie
>    >> 
>    >> [[alternative HTML version deleted]]
>    >> 
>    >> ______________________________________________
>   >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>    >> https://stat.ethz.ch/mailman/listinfo/r-help
>    >> PLEASE do read the posting guide
>    >> http://www.R-project.org/posting-guide.html
>  >> and provide commented, minimal, self-contained, reproducible code.
>
>    > ______________________________________________
>    > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>    > https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>   > and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list