How to save and restore a workspace

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

How to save and restore a workspace

jonnvan
Hello,
I recently downloaded R in hopes of learning to use it for statistics.
I have promptly run into a problem, as I am unable to save, and later recover, a workspace so I can resume work where I left off.
I am using Windows.
I indicate "yes" to the pop up after q().  Then when I later reopen R Console and click on File, I cannot get my prior workspace to appear in the R Console frame so I can resume work.
In the File drop down menu I have tried Load Workspace, Load History, Display file(s)..., opened R Type: R Workspace with no luck.
I have read about this in two different books, the R Manual, and R FAQs, used the RGui help function, and still cannot do it.
I have used Windows for years, but I am ignorant about programming.
Would appreciate any help you might offer.
I live in the Denver area, so if there are any local resources you could direct me to, I would be grateful for that as well.

Thank you,
Jon VanDeventer

Sent from my iPad
______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: How to save and restore a workspace

Jim Lemon-4
Hi Jon,
Saving your workspace doesn't mean that everything will be rerun when
you start a new R session. I just means that persistent objects like
data frames will be there. If you type:

objects()

you will see all of those things that were there when you ended in the
last session. Things like commands will be in the "history", so you
can retrieve them just as you did at the end of the last session (up
arrow). It may be a better solution if you save sequences of commands
as R script files (e.g. "something.R") as you can run them:

source("something.R")

and edit and save them again.

Jim

On Tue, Oct 24, 2017 at 9:12 AM,  <[hidden email]> wrote:

> Hello,
> I recently downloaded R in hopes of learning to use it for statistics.
> I have promptly run into a problem, as I am unable to save, and later recover, a workspace so I can resume work where I left off.
> I am using Windows.
> I indicate "yes" to the pop up after q().  Then when I later reopen R Console and click on File, I cannot get my prior workspace to appear in the R Console frame so I can resume work.
> In the File drop down menu I have tried Load Workspace, Load History, Display file(s)..., opened R Type: R Workspace with no luck.
> I have read about this in two different books, the R Manual, and R FAQs, used the RGui help function, and still cannot do it.
> I have used Windows for years, but I am ignorant about programming.
> Would appreciate any help you might offer.
> I live in the Denver area, so if there are any local resources you could direct me to, I would be grateful for that as well.
>
> Thank you,
> Jon VanDeventer
>
> Sent from my iPad
> ______________________________________________
> [hidden email] 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.

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

Re: How to save and restore a workspace

Bert Gunter-2
Suggestion:

Read the "Intro to R tutorial" that ships with R. Alternatively, there are
also many good online tutorials, some free, some not. You'll need to spend
some time and effort to learn R's basic data structures and paradigms even
if you don't get involved in any serious programming.

If this is not something you are willing or able to do, you might check
here for a point and click GUI interface that give you access to some of
R's basic functionality: http://socserv.mcmaster.ca/jfox/Misc/Rcmdr/  . You
will have to determine whether this serves your needs and priorities of
course.


Cheers,
Bert

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )

On Mon, Oct 23, 2017 at 3:45 PM, Jim Lemon <[hidden email]> wrote:

> Hi Jon,
> Saving your workspace doesn't mean that everything will be rerun when
> you start a new R session. I just means that persistent objects like
> data frames will be there. If you type:
>
> objects()
>
> you will see all of those things that were there when you ended in the
> last session. Things like commands will be in the "history", so you
> can retrieve them just as you did at the end of the last session (up
> arrow). It may be a better solution if you save sequences of commands
> as R script files (e.g. "something.R") as you can run them:
>
> source("something.R")
>
> and edit and save them again.
>
> Jim
>
> On Tue, Oct 24, 2017 at 9:12 AM,  <[hidden email]> wrote:
> > Hello,
> > I recently downloaded R in hopes of learning to use it for statistics.
> > I have promptly run into a problem, as I am unable to save, and later
> recover, a workspace so I can resume work where I left off.
> > I am using Windows.
> > I indicate "yes" to the pop up after q().  Then when I later reopen R
> Console and click on File, I cannot get my prior workspace to appear in the
> R Console frame so I can resume work.
> > In the File drop down menu I have tried Load Workspace, Load History,
> Display file(s)..., opened R Type: R Workspace with no luck.
> > I have read about this in two different books, the R Manual, and R FAQs,
> used the RGui help function, and still cannot do it.
> > I have used Windows for years, but I am ignorant about programming.
> > Would appreciate any help you might offer.
> > I live in the Denver area, so if there are any local resources you could
> direct me to, I would be grateful for that as well.
> >
> > Thank you,
> > Jon VanDeventer
> >
> > Sent from my iPad
> > ______________________________________________
> > [hidden email] 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.
>
> ______________________________________________
> [hidden email] 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.
>

        [[alternative HTML version deleted]]

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

Re: How to save and restore a workspace

Jeff Newmiller
In reply to this post by Jim Lemon-4
To be specific, the effect of loading packages with the "library" function is NOT saved when you save the workspace... and if you come back much later after you have updated some packages the old saved objects may not work well with those new packages. At the very least you have to re-load all necessary packages yourself before you load a saved workspace. Many users avoid ever using the "save workspace" option because it can cause old mistakes to come back and haunt you later.

This kind of issue has lead me to become quite systematic about writing R files (as Jim suggested below) that re-do all of my work on a given task (omitting the false starts needed to learn things) on each of my projects starting from a blank workspace. It may seem like a tedious approach to the beginner, but it is actually very comforting to know that I can look through every step and verify that it did what I wanted it to, without wondering how some particular intermediate result was computed six months ago and saved for later use. If one step is particularly slow, I may comment out (our put an "if" around) the statements that originally created and saved that object with saveRDS, and load it instead of recomputing it once I trust it. But the key is to always focus on building sequences of R statements, and later on building functions rather than poking and prodding a workspace like it was a spreadsheet.
--
Sent from my phone. Please excuse my brevity.

On October 23, 2017 3:45:29 PM PDT, Jim Lemon <[hidden email]> wrote:

>Hi Jon,
>Saving your workspace doesn't mean that everything will be rerun when
>you start a new R session. I just means that persistent objects like
>data frames will be there. If you type:
>
>objects()
>
>you will see all of those things that were there when you ended in the
>last session. Things like commands will be in the "history", so you
>can retrieve them just as you did at the end of the last session (up
>arrow). It may be a better solution if you save sequences of commands
>as R script files (e.g. "something.R") as you can run them:
>
>source("something.R")
>
>and edit and save them again.
>
>Jim
>
>On Tue, Oct 24, 2017 at 9:12 AM,  <[hidden email]> wrote:
>> Hello,
>> I recently downloaded R in hopes of learning to use it for
>statistics.
>> I have promptly run into a problem, as I am unable to save, and later
>recover, a workspace so I can resume work where I left off.
>> I am using Windows.
>> I indicate "yes" to the pop up after q().  Then when I later reopen R
>Console and click on File, I cannot get my prior workspace to appear in
>the R Console frame so I can resume work.
>> In the File drop down menu I have tried Load Workspace, Load History,
>Display file(s)..., opened R Type: R Workspace with no luck.
>> I have read about this in two different books, the R Manual, and R
>FAQs, used the RGui help function, and still cannot do it.
>> I have used Windows for years, but I am ignorant about programming.
>> Would appreciate any help you might offer.
>> I live in the Denver area, so if there are any local resources you
>could direct me to, I would be grateful for that as well.
>>
>> Thank you,
>> Jon VanDeventer
>>
>> Sent from my iPad
>> ______________________________________________
>> [hidden email] 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.
>
>______________________________________________
>[hidden email] 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.

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

Re: How to save and restore a workspace

MacQueen, Don
In reply to this post by Jim Lemon-4
Saving your workspace means that the variables you currently have defined in your session [ everything that shows up when you type ls() ] are saved to a file, by default named “.RData”. To restore the workspace, you use the “Load Workspace” command and navigate to the (same) .RData file. Its default location for Windows, as far as I know, is your “Documents” folder. So look there.

I see that you tried the Load Workspace command, and didn’t get what you were looking for. I just tested what I described above, and it did work. So either you didn’t navigate to and open .RData, or you have some other idea about what saving and loading a workspace means. Hopefully, it’s the former!

With some effort, you can learn to save different .RData files for different projects; for that see the R Windows FAQ.

By the way, this is much easier on Linux, and on Mac when working in a Terminal (command line) environment.

-Don

--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
Lab cell 925-724-7509
 
 

On 10/23/17, 3:45 PM, "R-help on behalf of Jim Lemon" <[hidden email] on behalf of [hidden email]> wrote:

    Hi Jon,
    Saving your workspace doesn't mean that everything will be rerun when
    you start a new R session. I just means that persistent objects like
    data frames will be there. If you type:
   
    objects()
   
    you will see all of those things that were there when you ended in the
    last session. Things like commands will be in the "history", so you
    can retrieve them just as you did at the end of the last session (up
    arrow). It may be a better solution if you save sequences of commands
    as R script files (e.g. "something.R") as you can run them:
   
    source("something.R")
   
    and edit and save them again.
   
    Jim
   
    On Tue, Oct 24, 2017 at 9:12 AM,  <[hidden email]> wrote:
    > Hello,
    > I recently downloaded R in hopes of learning to use it for statistics.
    > I have promptly run into a problem, as I am unable to save, and later recover, a workspace so I can resume work where I left off.
    > I am using Windows.
    > I indicate "yes" to the pop up after q().  Then when I later reopen R Console and click on File, I cannot get my prior workspace to appear in the R Console frame so I can resume work.
    > In the File drop down menu I have tried Load Workspace, Load History, Display file(s)..., opened R Type: R Workspace with no luck.
    > I have read about this in two different books, the R Manual, and R FAQs, used the RGui help function, and still cannot do it.
    > I have used Windows for years, but I am ignorant about programming.
    > Would appreciate any help you might offer.
    > I live in the Denver area, so if there are any local resources you could direct me to, I would be grateful for that as well.
    >
    > Thank you,
    > Jon VanDeventer
    >
    > Sent from my iPad
    > ______________________________________________
    > [hidden email] 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.
   
    ______________________________________________
    [hidden email] 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.
   

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

Re: How to save and restore a workspace

PIKAL Petr
Hi Don

This is matter of opinion

> By the way, this is much easier on Linux, and on Mac when working in a
> Terminal (command line) environment.

There is some basic menu items in RGui which is not in terminal. This could be quite confusing if you are used to have each project in separate directory and want to switch to it (I know about setwd command however in that case point and click is much more convenient).

But as I said, it is matter of opinion.

For Jon

I usually do not start R from its icon. I make a new folder for each project for which I want to use R and keep .RData and .Rhistory in it.

Try to set a new folder named e.g. "stat" somewhere.
Locate .RData and .Rhistory files and copy it to this folder.
Double click on .RData to start R (or select R as a program to open this file)
You can open .Rhistory in any suitable text editor (Notepad, Tinn, ...) to reuse commands in it.

Alternative:

After starting R, you can change working directory (setwd or through menu item). After this change, any saved object together with .RData or Rhistory will go into this directory. You could also set a shortcut icon to this directory on your desktop by copiing original icon, renaming it and manually changing desired directory.

Cheers
Petr

> -----Original Message-----
> From: R-help [mailto:[hidden email]] On Behalf Of MacQueen,
> Don
> Sent: Wednesday, October 25, 2017 11:05 PM
> To: Jim Lemon <[hidden email]>; [hidden email]
> Cc: r-help mailing list <[hidden email]>
> Subject: Re: [R] How to save and restore a workspace
>
> Saving your workspace means that the variables you currently have defined in
> your session [ everything that shows up when you type ls() ] are saved to a file,
> by default named “.RData”. To restore the workspace, you use the “Load
> Workspace” command and navigate to the (same) .RData file. Its default
> location for Windows, as far as I know, is your “Documents” folder. So look
> there.
>
> I see that you tried the Load Workspace command, and didn’t get what you
> were looking for. I just tested what I described above, and it did work. So either
> you didn’t navigate to and open .RData, or you have some other idea about
> what saving and loading a workspace means. Hopefully, it’s the former!
>
> With some effort, you can learn to save different .RData files for different
> projects; for that see the R Windows FAQ.
>
>
> -Don
>
> --
> Don MacQueen
> Lawrence Livermore National Laboratory
> 7000 East Ave., L-627
> Livermore, CA 94550
> 925-423-1062
> Lab cell 925-724-7509
>
>
>
> On 10/23/17, 3:45 PM, "R-help on behalf of Jim Lemon" <r-help-bounces@r-
> project.org on behalf of [hidden email]> wrote:
>
>     Hi Jon,
>     Saving your workspace doesn't mean that everything will be rerun when
>     you start a new R session. I just means that persistent objects like
>     data frames will be there. If you type:
>
>     objects()
>
>     you will see all of those things that were there when you ended in the
>     last session. Things like commands will be in the "history", so you
>     can retrieve them just as you did at the end of the last session (up
>     arrow). It may be a better solution if you save sequences of commands
>     as R script files (e.g. "something.R") as you can run them:
>
>     source("something.R")
>
>     and edit and save them again.
>
>     Jim
>
>     On Tue, Oct 24, 2017 at 9:12 AM,  <[hidden email]> wrote:
>     > Hello,
>     > I recently downloaded R in hopes of learning to use it for statistics.
>     > I have promptly run into a problem, as I am unable to save, and later
> recover, a workspace so I can resume work where I left off.
>     > I am using Windows.
>     > I indicate "yes" to the pop up after q().  Then when I later reopen R Console
> and click on File, I cannot get my prior workspace to appear in the R Console
> frame so I can resume work.
>     > In the File drop down menu I have tried Load Workspace, Load History,
> Display file(s)..., opened R Type: R Workspace with no luck.
>     > I have read about this in two different books, the R Manual, and R FAQs,
> used the RGui help function, and still cannot do it.
>     > I have used Windows for years, but I am ignorant about programming.
>     > Would appreciate any help you might offer.
>     > I live in the Denver area, so if there are any local resources you could direct
> me to, I would be grateful for that as well.
>     >
>     > Thank you,
>     > Jon VanDeventer
>     >
>     > Sent from my iPad
>     > ______________________________________________
>     > [hidden email] 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.
>
>     ______________________________________________
>     [hidden email] 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.
>
>
> ______________________________________________
> [hidden email] 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.

________________________________
Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či zpožděním přenosu e-mailu.

V případě, že je tento e-mail součástí obchodního jednání:
- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a to z jakéhokoliv důvodu i bez uvedení důvodu.
- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce s dodatkem či odchylkou.
- trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným dosažením shody na všech jejích náležitostech.
- odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi či osobě jím zastoupené známá.

This e-mail and any documents attached to it may be confidential and are intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. Delete the contents of this e-mail with all attachments and its copies from your system.
If you are not the intended recipient of this e-mail, you are not authorized to use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by modifications of the e-mail or by delay with transfer of the email.

In case that this e-mail forms part of business dealings:
- the sender reserves the right to end negotiations about entering into a contract in any time, for any reason, and without stating any reasoning.
- if the e-mail contains an offer, the recipient is entitled to immediately accept such offer; The sender of this e-mail (offer) excludes any acceptance of the offer on the part of the recipient containing any amendment or variation.
- the sender insists on that the respective contract is concluded only upon an express mutual agreement on all its aspects.
- the sender of this e-mail informs that he/she is not authorized to enter into any contracts on behalf of the company except for cases in which he/she is expressly authorized to do so in writing, and such authorization or power of attorney is submitted to the recipient or the person represented by the recipient, or the existence of such authorization is known to the recipient of the person represented by the recipient.
______________________________________________
[hidden email] 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.