get.backup
retrieves backups of a function. restore.all.backups
creates objects from their most recent backups. create.backups
creates backup files for all hitherto-unbacked-up functions in a search environment. For get.backup
or restore.all.backups
to work, all backups must have been created using the fixr
system (or create.backups
).get.backup( name, where=1, rev=TRUE, zap.name=TRUE)
restore.all.backups( where=2)
create.backups( pos=1)
"funname" <-
at the start of each backup is removedfixr
and FF
are able to maintain text-file backups of source code, in a directory ".Backup.mvb" below the task directory. The directory will contain a file called "index", plus files BU1, BU2, etc. "index" shows the correspondence between function names and BUx files. Each BUx file contains multiple copies of the source code, with the oldest first. Even if a function is removed (or move
d) from the workspace, its BUx file and "index" entry are not deleted.
The number of backups kept is controlled by options(backup.fix)
, a numeric vector of length 2. The first element is how many backups to keep from the current Rsession. The second is how many previous Rsessions to keep the final version of the source code from. Older versions get discarded. I use c(5,2)
. If you want to use the backup facility, you'll need to set this option in your .First
. If the option is not set, no backups happen. If set, then every call to Save
or Save.pos
will create backups for all previously-unbackupped functions, by automatically calling create.backups
. create.backups
can also be called manually, to create the backup directory, index, and backup files for all functions in the currently-top task.
restore.all.backups
always restores to the current workspace, regardless of where it is restoring from. This is a safety feature. If you screw up the .Rdata file in task mytask
and want to restore the functions in it from backups, the safe way to do it is to cd(mytask)
, then cd(restore)
to create a subtask, then restore.all.backups()
to create "masking" versions in mytask/restore
. Then you can check the restorees and move( what=<>, ., ..)
to put them back into mytask
. Set overwrite.by.default=TRUE
in the move
call if you don't want to check each file. The more risky way is just to cd(mytask)
and restore.all.backups(1)
-- this will overwrite any more recent versions that you may want to keep.
get.backup
offers more control, in that you get all (available) backup versions of a given function, but can only be called for one function at a time. You can also examine the backup files in a text editor, of course.
The function fix.order
uses the access dates of backup files to list your functions sorted by date order.
move
will also move backup files and update INDEX files appropriately.fixr
, cd
, move
## Need some backups first
get.backup( "myfun", "package:myfun")[[1]] # returns most recent backup only
cat( get.backup( "myfun", "package:myfun", zap=FALSE)[[1]][1])
# shows "myfun" <- function\dots
# restore.all.backups(1) # really don't run this
Run the code above in your browser using DataLab