R: Save R and ff objects

ffsave {ff} | R Documentation

## Save R and ff objects

### Description

`ffsave` writes an external representation of R and ff objects to an `ffarchive`. The objects can be read back from the file at a later date by using the function `ffload`.

### Usage

    ffsave(...
    , list = character(0L)
    , file = stop("'file' must be specified")
    , envir = parent.frame()
    , rootpath = NULL
    , add = FALSE

    , move = FALSE
    , compress = !move
    , compression_level = 6
    , precheck=TRUE
    )
    ffsave.image(file = stop("'file' must be specified"), safe = TRUE, ...)

### Arguments

`...` | For `ffsave` the names of the objects to be saved (as symbols or character strings), for `ffsave.image` further arguments passed to `ffsave`
`list` | A character vector containing the names of objects to be saved.
`file` | A name for the the `ffarchive`, i.e. the two files `<file>.RData` and `<file>.ffData`
`envir` | environment to search for objects to be saved.
`add` | logical indicating whether the objects shall be added to the `ffarchive` (in this case `rootpath` is taken from an existing archive)

`move` | logical indicating whether ff files shall be moved instead of copied into the `<file>.ffData`
`compress` | logical specifying whether saving to a named file is to use compression.
`compression_level` | compression level passed to `zip`, default 6
`rootpath` | optional path component that all all ff files share and that can be dropped/replaced when calling `ffload`
`precheck` | logical: should the existence of the objects be checked before starting to save (and in particular before opening the file/connection)?
`safe` | logical. If `TRUE`, a temporary file is used for creating the saved workspace. The temporary file is renamed to `<file>.ffData` if the save succeeds. This preserves an existing workspace `<file>.ffData` if the save fails, but at the cost of using extra disk space during the save.

### Details

`ffsave` stores objects and ff files in an `ffarchive` named `<file>`: i.e. it saves all specified objects via `save` in a file named `<file>.RData` and saves all ff files related to these objects in a zipfile named `<file>.ffData` using an external `zip` utility.
By default files are stored relative to the `rootpath="\"} and will be restored relative to \code{"\"` (in its original location). By providing a partial path prefix via argument `rootpath` the files are stored relative to this `rootpath`. The `rootpath` is stored in the `<file>.RData` with the name `.ff.rootpath`. I.e. even if the ff objects were saved with argument `rootpath` to `ffsave`, `ffload` by default restores in the original location. By using argument `rootpath` to `ffload` you can restore relative to a different `rootpath` (and using argument `rootpath` to `ffsave` gave you shorter relative paths)
By using argument `add` in `ffsave` you can add more objects to an existing `ffarchive` and by using argument `list` in `ffload` you can selectively restore objects.
The content of the `ffarchive` can be inspected using `ffinfo` before actually loading any of the objects.
The `ffarchive` can be deleted from disk using `ffdrop`.

### Value

a character vector with messages returned from the `zip` utility (one for each ff file zipped)

### Note

The ff files are not platform-independent with regard to byte order. For large files and the zip64 format use `zip 3.0` and `unzip 6.0` from http://www.info-zip.org/.

### Author(s)

Jens Oehlschlägel

### See Also

`ffinfo` for inspecting the content of the `ffarchive`
`ffload` for loading all or some of the `ffarchive`
`ffdrop` for deleting one or more `ffarchives`

### Examples

      ## Not run:
      message("let's create some ff objects")
      n <- 8e3
      a <- ff(sample(n, n, TRUE), vmode="integer", length=n, filename="d:/tmp/a.ff")
      b <- ff(sample(255, n, TRUE), vmode="ubyte", length=n, filename="d:/tmp/b.ff")
      x <- ff(sample(255, n, TRUE), vmode="ubyte", length=n, filename="d:/tmp/x.ff")
      y <- ff(sample(255, n, TRUE), vmode="ubyte", length=n, filename="d:/tmp/y.ff")
      z <- ff(sample(255, n, TRUE), vmode="ubyte", length=n, filename="d:/tmp/z.ff")
      df <- ffdf(x=x, y=y, z=z)
      rm(x,y,z)

      message("save all of them")
      ffsave.image("d:/tmp/x")
      str(ffinfo("d:/tmp/x"))

      message("save some of them with shorter relative pathnames ...")
      ffsave(a, b, file="d:/tmp/y", rootpath="d:/tmp")
      str(ffinfo("d:/tmp/y"))

      message("... and add others later")
      ffsave(df, add=TRUE, file="d:/tmp/y", rootpath="d:/tmp")
      str(ffinfo("d:/tmp/y"))

      message("... and add others later")
      system.time(ffsave(a, file="d:/tmp/z", move=TRUE))
      ffinfo("d:/tmp/z")

      message("let's delete/close/remove all objects")
      close(a)  # no file anymore, since we moved a into the ffarchive
      delete(b, df)
      rm(df, a, b, n)
      message("prove it")
      ls()

      message("restore all but ff files in a different directory")
      system.time(ffload("d:/tmp/x", rootpath="d:/tmp2"))
      lapply(ls(), function(i)filename(get(i)))

      delete(a, b, df)
      rm(df, a, b)

      ffdrop(c("d:/tmp/x", "d:/tmp/y", "d:/tmp/z"))

    ## End(Not run)

[Package ff version 2.2-13 Index]