[R] PowerCut Killed R - is my code retrievable?
Ted.Harding at manchester.ac.uk
Thu Aug 20 01:21:47 CEST 2009
On 19-Aug-09 22:35:01, Barry Rowlingson wrote:
> On Wed, Aug 19, 2009 at 10:57 PM, Polwart Calum (County Durham and
> Darlington NHS Foundation Trust)<calum.polwart at nhs.net> wrote:
>> I've been tweaking code for several days on and off in R, cut and
>> pasting in from a text editor (I just leave them open all the time).
>> _I think I got something that was usable but then a powersurge tripped
>> the fuses and unfortunately the machine I was working on doesn't have
> a UPS.
> So you were just using the text editor as a scratch pad, and not
> saving it? A half-decent text editor should be saving things to disk
> as you go. For example, in emacs, if your emacs dies while editing a
> file then when you restart it, it will notice and offer to restore it
> from its "restore" file. If you were using emacs you might have files
> like #foo.R# which are emacs' auto-restore files. Other editors might
> do other things - possibly leaving files in /tmp on a Linux system
> (but they might get zapped by a reboot).
To follow up on what Barry wrote above: Don't be put off by the
recommendation to use EMACS (which is not to everyone's taste).
I use vim, which does much the same sort of thing: there is a hidden
".whatever.swp" file which contains a back-trackable history of
the editing changes that have been made to the file. So, if you get
a crash, on re-opening the file in vim you are asked if you want to
"recover". The ".swp" file is *not* zapped by a reboot!
But, in any case, it is very wise to frequently and deliberately
save the current state of your file. In vim's command mode, all you
need to do is to type ":w" and it is saved. And to get into command
mode (or make sure that you are in it), just press "<ESC>".
So "<ESC>:w" does it. Takes 0.5 seconds.
Again, what I routinely do (in Linux) when developing R code is to
have two terminal windows open. In one I am running R. In the other,
beside it, I am editing a file of R code. To run code in R that has
been entered in the "code" window, I just highlight it with the
mouse in the "code" window, and then paste it into the "R" window.
This method also has the advantage that it is easy to scroll back
to code entered earlier, and either paste it into the R window,
or copy it down in the "code" window if you want to modify it.
(The "code" window does not have to be a ".R" file to be sourced
by R -- though it may later become one. Its function is to preserve
a trace of what you have done, and make it easy to modify things
until you get what you want).
>> Also - is there a better way for the future? _I know some people use
>> IDE's but is that for serious programming or for building a small
>> function and tweaking it?
> Tip #1 is save your text file scratchpads!
> Tip #2 is save your R session regularly (just do 'save.image()' and
> it will save your current R session objects in a .RData file)
> Tip #3 is you could use emacs + ESS as an IDE - you run R within
> emacs, giving you cut n paste of code, syntax highlighting, session
> transcripts, and emacs' protection from data loss on a crash!
> R-help at r-project.org mailing list
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 20-Aug-09 Time: 00:21:42
------------------------------ XFMail ------------------------------
More information about the R-help