Deleting the file behind an ff object
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.
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, ...)
x |
an ff or ram object |
... |
further arguments (not used) |
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.
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.
Deletion of ff files can be triggerd automatically via three routes:
if an ff object with a 'delete' finalizer is removed
if an ff object was created with fffinonexit=TRUE
the finalizer is also called when R shuts down.
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:
name the file AND use fffinalizer="close"
name the file AND use fffinalizer="deleteIfOpen"
AND close the ff object before leaving R
name the file AND use fffinalizer="delete"
AND use fffinonexit=FALSE
Jens Oehlschlägel
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)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.