Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

delete

Deleting the file behind an ff object


Description

The generic delete deletes the content of an object without removing the object itself. The generic deleteIfOpen does the same, but only if is.open returns TRUE.

Usage

delete(x, ...)
deleteIfOpen(x, ...)
## S3 method for class 'ff'
delete(x, ...)
## S3 method for class 'ffdf'
delete(x, ...)
## S3 method for class 'ff_pointer'
delete(x, ...)
## Default S3 method:
delete(x, ...)
## S3 method for class 'ff'
deleteIfOpen(x, ...)
## S3 method for class 'ff_pointer'
deleteIfOpen(x, ...)

Arguments

x

an ff or ram object

...

further arguments (not used)

Details

The proper sequence to fully delete an ff object is: delete(x);rm(x), where delete.ff frees the Memory Mapping resources and deletes the ff file, leaving intact the R-side object including its class, physical and virtual attributes. The default method is a compatibility function doing something similar with ram objects: by assiging an empty list to the name of the ram object to the parent frame we destroy the content of the object, leaving an empty stub that prevents raising an error if the parent frame calls the delete(x);rm(x) sequence.
The deleteIfOpen does the same as delete but protects closed ff objects from deletion, it is mainly intended for use through a finalizer, as are the ff_pointer methods.

Value

delete returns TRUE if the/all ff files could be removed and FALSE otherwise.
deleteIfOpen returns TRUE if the/all ff files could be removed, FALSE if not and NA if the ff object was open.

Note

Deletion of ff files can be triggerd automatically via three routes:

  1. if an ff object with a 'delete' finalizer is removed

  2. if an ff object was created with fffinonexit=TRUE the finalizer is also called when R shuts down.

  3. if an ff object was created in getOption("fftempdir"), it will be unlinked together with the fftempdir .onUnload

Thus in order to retain an ff file, one has to create it elsewhere than in fftempdir with a finalizer that does not destroy the file (by default files outside fftempdir get a 'close' finalizer') i.e. one of the following:

  1. name the file AND use fffinalizer="close"

  2. name the file AND use fffinalizer="deleteIfOpen" AND close the ff object before leaving R

  3. name the file AND use fffinalizer="delete" AND use fffinonexit=FALSE

Author(s)

Jens Oehlschlägel

See Also

Examples

message('create the ff file outside getOption("fftempir"), 
    it will have default finalizer "close", so you need to delete it explicitely')
  x <- ff(1:12, pattern="./ffexample")
  delete(x)
  rm(x)

ff

Memory-Efficient Storage of Large Data on Disk and Fast Access Functions

v4.0.4
GPL-2 | GPL-3 | file LICENSE
Authors
Daniel Adler [aut], Christian Gläser [aut], Oleg Nenadic [aut], Jens Oehlschlägel [aut, cre], Martijn Schuemie [aut], Walter Zucchini [aut]
Initial release
2020-10-13

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.