how to load R data file into a structure?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

how to load R data file into a structure?

LosemindL
Hi all,

I have already some important variables in the current R session;

and I wanted to load some rData file which was saved during the last R
session using "save.image"...

But how do I avoid the newly loaded data/variables messing with my existing
data/variables?

In Matlab, I can do:

mynewdata=load("imagefromlastRsession.rData")

and then I can access the variables therein as follows:

mynewdata.variable1
 mynewdata.variable2
 mynewdata.variable3
...
...
...

As you can see, this way, these variables won't interfere with my existing
variables in the current R session...

How to do that?

Thanks a lot!

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
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.
Reply | Threaded
Open this post in threaded view
|

Re: how to load R data file into a structure?

Michael Weylandt
Read the help page for load....particularly the part about environments.

E.g.,

a <- 3
save("a", file = "temp.RData")

a <- 4

env <- new.env()
load("temp.RData", env)

identical(a, 4)
identical(env$a, 3)

Michael

On Sat, Jan 21, 2012 at 9:54 PM, Michael <[hidden email]> wrote:

> Hi all,
>
> I have already some important variables in the current R session;
>
> and I wanted to load some rData file which was saved during the last R
> session using "save.image"...
>
> But how do I avoid the newly loaded data/variables messing with my existing
> data/variables?
>
> In Matlab, I can do:
>
> mynewdata=load("imagefromlastRsession.rData")
>
> and then I can access the variables therein as follows:
>
> mynewdata.variable1
>  mynewdata.variable2
>  mynewdata.variable3
> ...
> ...
> ...
>
> As you can see, this way, these variables won't interfere with my existing
> variables in the current R session...
>
> How to do that?
>
> Thanks a lot!
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> 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.

______________________________________________
[hidden email] mailing list
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.
Reply | Threaded
Open this post in threaded view
|

Re: how to load R data file into a structure?

LosemindL
That works greatly. Thanks a lot!

On Sat, Jan 21, 2012 at 8:59 PM, R. Michael Weylandt <
[hidden email]> wrote:

> Read the help page for load....particularly the part about environments.
>
> E.g.,
>
> a <- 3
> save("a", file = "temp.RData")
>
> a <- 4
>
> env <- new.env()
> load("temp.RData", env)
>
> identical(a, 4)
> identical(env$a, 3)
>
> Michael
>
> On Sat, Jan 21, 2012 at 9:54 PM, Michael <[hidden email]> wrote:
> > Hi all,
> >
> > I have already some important variables in the current R session;
> >
> > and I wanted to load some rData file which was saved during the last R
> > session using "save.image"...
> >
> > But how do I avoid the newly loaded data/variables messing with my
> existing
> > data/variables?
> >
> > In Matlab, I can do:
> >
> > mynewdata=load("imagefromlastRsession.rData")
> >
> > and then I can access the variables therein as follows:
> >
> > mynewdata.variable1
> >  mynewdata.variable2
> >  mynewdata.variable3
> > ...
> > ...
> > ...
> >
> > As you can see, this way, these variables won't interfere with my
> existing
> > variables in the current R session...
> >
> > How to do that?
> >
> > Thanks a lot!
> >
> >        [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > [hidden email] mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html>
> > and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
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.