I realize that I overwrote an .R file that took me some time to create. Is it possible to see in my .RData the commands that I ran? I always saved my files as external scripts and have never used the .RData file before so I don't really know what to do and am afraid of loosing it forever.
RData file contains all objects in your current workspace.
The easiest way to load the data into R is to double-click on the particular file yourfile. RData after you download it to your computer. This will open in RStudio only if you have associated the . RData files with RStudio.
To access file click File and then load workspace. A dialog box will appear, browse to the folder where you saved the . RData file and click open.
Do you have a file in your directory named ".Rhistory"? This file might be hidden on Linux systems.
Read up the help page ?history
This is not really a direct answer to your question, but some advice from The Pragmatic Programmer that has served me well time and time again to avoid situations like this:
Always Use Source Code Control
If a process was worth the time it took to record the steps in a .R
file, then it should be protected by a source code control system. This gives you many important benefits, two of which are:
You can recover or rewind your files which provides protection against accidental deletion or modifications that, an hour later, start to seem like they were not such a good idea after all.
Your work is backed up in one or more locations. Preferably on different computers.
If you have never used source code control before, here are some resources to get you started:
Git is a great system that has the benefit of being distributed which makes your files very hard to loose. gitref.org is a greate place to learn about Git and GitHub provides great hosting for off-site Git repositories.
Mercurial is another good distributed system. Joel Spolsky, one of the cofounders of this very site, wrote an excellent guide at hginit.com. Bitbucket is a great place to host off-site Mercurial repositories---they even allow unlimited private repositories if you need to control access to your work.
Learning source code control was without a doubt the most valuable investment I have ever made in a programming tool. It pays its self back the first time a situation like this comes up.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With