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.
Does R hold the command data in cache some place? I've purposefully not opened R since the crash so that if it did I don't over write it?
I guess what I'm wanting is the equivalent of the linux up arrow which repeats the last line. i know that exists in R but from what I recall it didn't work when you close the R session. Is that stored in a hidden file someplace that I could copy?
Its not a huge piece of code or anything - but it was code I tweaked over several stages as I'm new to R and so it was part of my learning process.
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?
Thanks
Calum
********************************************************************************************************************
This message may contain confidential information. If yo...{{dropped:21}}
PowerCut Killed R - is my code retrievable?
8 messages · Polwart Calum (County Durham and Darlington NHS Foundation Trust), Rolf Turner, Barry Rowlingson +4 more
On 20/08/2009, at 9:57 AM, Polwart Calum (County Durham and
Darlington NHS Foundation Trust) 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. Does R hold the command data in cache some place? I've purposefully not opened R since the crash so that if it did I don't over write it? I guess what I'm wanting is the equivalent of the linux up arrow which repeats the last line. i know that exists in R but from what I recall it didn't work when you close the R session. Is that stored in a hidden file someplace that I could copy? Its not a huge piece of code or anything - but it was code I tweaked over several stages as I'm new to R and so it was part of my learning process. 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?
If you've been cut-and-pasting from a text editor, then your commands
*might* be in the file .Rhistory. Unfortunately this history gets saved
only when you exit R (and by default only when you also say ``yes'' to
saving the workspace) or if you explicitly savehistory().
After a powersurge, the R workspace and history almost surely will
not be
saved, so it is highly probable that you are SOL. Unless you closed
the R session (and save the workspace) before the power cut. Bummer.
Good luck.
cheers,
Rolf Turner
######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}
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).
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! Barry
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). Ted.
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! Barry
______________________________________________ R-help at r-project.org 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.
-------------------------------------------------------------------- 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 ------------------------------
On Thu, 20-Aug-2009 at 12:21AM +0100, Ted Harding wrote:
[....] |> 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. It's even easier using ESS -- highlight in your "code" buffer, press your designated function key and the code will be run in the *R* buffer -- or you can use another function key to run code line by line, or, etc. etc. I must admit I didn't like Emacs for the first week or so but when I saw how easy it was to manage code, I decided it was worth the effort to get used to the strange old paradigm which had been developed before the invention of the mouse. I'd also admit that I've seen people do things amazingly quickly using vi -- despite its strange jumping from command mode to insert mode. As others have indicated, whatever you use, it makes good sense to keep a file of the code that you use. Rerunning is something I do as a rule, not an exception. It's particularly useful when follow up work arrives which can reuse the same code or a slightly modified version of it. [...]
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
___ Patrick Connolly
{~._.~} Great minds discuss ideas
_( Y )_ Average minds discuss events
(:_~*~_:) Small minds discuss people
(_)-(_) ..... Eleanor Roosevelt
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
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?
What about a version control system to (locally) save the different stages of your script files? (I use git but Subversion (SVN) may be easier and do the job). Cheers, Hans-Peter
Rolf Write:
If you've been cut-and-pasting from a text editor, then your commands *might* be in the file .Rhistory. Unfortunately this history gets saved only when you exit R (and by default only when you also say ``yes'' to saving the workspace) or if you explicitly savehistory().
Was hoping there was some thing like that... but like you say it wasn't a planned exit so its not there --
Barry wrote:
So you were just using the text editor as a scratch pad, and not saving it?
Exactly
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.
Yeh thats what I was expecting to happen. I can't actually remember but I think it was gedit that I had open although sometimes I use kate. Neither have autorecoverry as I now know. Both can recover (possibly) files that had once been saved but it seems I never saved it - nit was literally just a big temporary, editable clipboard!
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).
It seems only if you hit save once then you may get temporary copies...! I've never liked emacs for other programming stuff - but will take another look at it. --
Ted wrote:
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).
Took the words out of my mouth
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!
Good to know. I used to use vi quite a lot in my command line linux days. These days it seems cumbersome on my linux PC but works fine on my server! Must be a configuration issue...
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.
Exactly what I was doing. Sounds like emacs with ESS has this even slicker - highlight and run. I just need to save the stuff! --
Ellison wrote:
Use a text editor or something specific to R like Tinn-R and _save early and often_.
Tinn-R is window$ only. I've played with RKWard and found it cumbersome plus it doesn't put my commands and its commands together so you don't get a command line History. Looking at sciViews-K just now. I currently use Eclipse as my DIE for PHP programming so I'll look at that too. I guess where I'm struggling is I don't really rate what I'm doing as programming becasue I'm not writing R plugins just some functions... Mind you just having some R context sensitive text / syntax highlighting may be an advantage. --
Hans wrote:
What about a version control system to (locally) save the different stages of your script files? (I use git but Subversion (SVN) may be easier and do the job).
My changes were typically one line at a time - and re-run it. I could remember what it was if it didn't do it (or use undo). But if this gets big then SVN etc might be worth it. I have no hands on expereince with GIT - one of my PHP projects has been discussing moveing to GIT / Bazzar for about 6 months. I see the advantage for them as they have multiple coders - is there some advanatge i might have missed for a lone programmer (sorry going well OT).
Clearly either doesn't work if I don't save the file!
Thanks BTW for all the posts back - one of my best responded to queries!
Calum
********************************************************************************************************************
This message may contain confidential information. If yo...{{dropped:21}}
On Thu, 2009-08-20 at 20:46 +0100, Polwart Calum (County Durham and <snip />
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.
Yeh thats what I was expecting to happen. I can't actually remember but I think it was gedit that I had open although sometimes I use kate. Neither have autorecoverry as I now know. Both can recover (possibly) files that had once been saved but it seems I never saved it - nit was literally just a big temporary, editable clipboard!
In gedit, Edit > Preferences, then select the Editor tab. Check the Autosave files box and set a low-ish number to suit your needs. By the looks of things, gedit will create backup files, but IIRC this happens when you save, so the backup contains the version before your most recent save. It doesn't maintain a recovery file like emacs. So the autosave option is the best option to avoid large losses if you use gedit. HTH G
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%