简体   繁体   English

使用.RData文件

[英]Using the .RData file

I realize that I overwrote an .R file that took me some time to create. 我意识到我覆盖了一个花了我一些时间来创建的.R文件。 Is it possible to see in my .RData the commands that I ran? 是否有可能在我的.RData中看到我运行的命令? 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文件,所以我真的不知道该怎么做而且害怕永远丢失它。

Do you have a file in your directory named ".Rhistory"? 你的目录中有一个名为“.Rhistory”的文件吗? This file might be hidden on Linux systems. 此文件可能在Linux系统上隐藏。

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. 如果一个进程值得记录.R文件中的步骤所花费的时间,那么它应该受到源代码控制系统的保护。 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. Git是一个很好的系统,具有分发的优势,使您的文件很难松散。 gitref.org is a greate place to learn about Git and GitHub provides great hosting for off-site Git repositories. gitref.org是一个了解Git的好地方, GitHub为异地Git存储库提供了很好的托管服务。

  • Mercurial is another good distributed system. Mercurial是另一个优秀的分布式系统。 Joel Spolsky, one of the cofounders of this very site, wrote an excellent guide at hginit.com . Joel Spolsky是这个网站的共同创始人之一,他在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. Bitbucket是托管异地Mercurial存储库的好地方 - 如果您需要控制对工作的访问,它们甚至允许无限制的私有存储库。

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're using GNU/Linux distro, there's a great chance that you already have backups in your working directory. 如果您使用的是GNU / Linux发行版,那么您工作目录中的备份很可能已经存在。 All you have to do is to use: 您所要做的就是使用:

  • in bash shell: 在bash shell中:

    ls -a | grep ~$

  • in R: 在R:

    dir(all.files = TRUE, pattern = "~$")

Note that -a and all.files = TRUE are needed only if you want to search hidden files (beginning with . ), otherwise you can easily omit it. 请注意,仅当您要搜索隐藏文件(以.开头)时才需要-aall.files = TRUE ,否则您可以轻松省略它。

But you should definitely use Git or SVN or other VCS, as Sharpie already suggested. 但是你应该使用Git或SVN或其他VCS,正如Sharpie已经建议的那样。 I would recommend Git (mostly because of GitHub). 我会推荐Git(主要是因为GitHub)。 Though that's only useful if you're hosting an open-source project, otherwise you'll have to pay for GitHub services (and I assume you'd like to skip that one, right?) 虽然这只有在你举办一个开源项目时才有用,否则你将不得不为GitHub服务付费(我想你想跳过那个,对吧?)

我相信.RData与运行save.image()会得到的结果相同 - 它会保存您在键入ls()时看到的所有内容ls()您可以通过将其拖入R控制台或运行命令来恢复它load(".RData")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM