gl.fbm.cleanup: Removes backing files of file-backed objects that are no...

View source: R/gl.fbm.cleanup.r

gl.fbm.cleanupR Documentation

Removes backing files of file-backed objects that are no longer used

Description

File-backed (FBM) dartR objects (see gl.gen2fbm) keep their genotypes in a backing file (.bk). Every subset, filter or imputation of a file-backed object writes a new backing file. dartR deletes a backing file automatically once no object in the R session uses it any more, when R's garbage collector removes the last such object.

gl.fbm.cleanup() forces that step: it runs the garbage collector, deletes the backing files that are no longer used, and reports what is left. Use it in long sessions, or before checking the free disk space.

Usage

gl.fbm.cleanup(verbose = NULL)

Arguments

verbose

Verbosity: 0, silent or fatal errors; 1, begin and end; 2, progress log; 3, progress and results summary; 5, full report [default NULL, adopting the global verbosity set by gl.set.verbosity(), or 2 if no global is set].

Details

Only backing files created by dartR in the current session are ever deleted. A backing file named by the user (argument backingfile of gl.gen2fbm, cbind or rbind) is never deleted.

On Windows a backing file cannot be deleted while it is still memory-mapped, which it can be for a short while after its last object is removed. Such files are deleted at the next attempt (by this function, or when dartR creates the next backing file).

Backing files are placed in getOption("FBM.dir"), by default the session temporary folder, which R deletes at the end of the session. If FBM.dir is set to another folder, files that could not be deleted when R closed can remain there; they can be deleted by hand once no R session uses them.

A file stays while anything in the session still refers to its object. ggplot2 keeps the last plot drawn (for ggsave() and last_plot()), and that plot refers to the input object of the dartR function that drew it, so one earlier backing file can stay in use until the next plot is drawn.

Objects saved with saveRDS() and loaded again with readRDS() in the same session are not known to dartR: their backing file can be deleted when the original object is removed. Use gl.save and gl.load instead.

Value

Invisibly, a list with the number and size (Mb) of the backing files deleted (deleted, deleted.mb), still in use (in.use, in.use.mb) and still waiting to be deleted (pending).

Author(s)

Author(s): Bernd Gruber. Custodian: Bernd Gruber – Post to https://groups.google.com/d/forum/dartr

See Also

gl.gen2fbm, gl.save

Other data manipulation: gl.add.indmetrics(), gl.define.pop(), gl.drop.ind(), gl.drop.loc(), gl.drop.pop(), gl.edit.recode.pop(), gl.fbm2gen(), gl.gen2fbm(), gl.impute(), gl.join(), gl.keep.ind(), gl.keep.loc(), gl.keep.pop(), gl.make.recode.ind(), gl.make.recode.pop(), gl.merge.pop(), gl.reassign.ind(), gl.reassign.pop(), gl.recode.ind(), gl.recode.pop(), gl.rename.pop(), gl.sample(), gl.sim.genotypes(), gl.sort(), gl.subsample.ind(), gl.subsample.loc(), gl.subsample.loci()

Examples

x <- gl.gen2fbm(testset.gl)
for (i in 1:5) x <- x[-1, ]   # each subset writes a new backing file
gl.fbm.cleanup()

dartR.base documentation built on Nov. 18, 2026, 9:06 a.m.