Learn R Programming

ff (version 4.5.0)

filename: Get or set filename

Description

Get or set filename from ram or ff object via the filename and filename<- generics or rename all files behind a ffdf using the pattern<- generic.

Usage

filename(x, ...)
filename(x, ...) <- value
# S3 method for default
filename(x, ...)
# S3 method for ff_pointer
filename(x, ...)
# S3 method for ffdf
filename(x, ...)
# S3 method for ff
filename(x, ...) <- value
pattern(x, ...)
pattern(x, ...) <- value
# S3 method for ff
pattern(x, ...)
# S3 method for ff
pattern(x, ...) <- value
# S3 method for ffdf
pattern(x, ...) <- value

Value

filename and pattern return a character filename or pattern. For ffdf returns a list with one filename element for each physical component. The assignment functions return the changed object, which will keep the change even without re-assigning the return-value

Arguments

x

a ram or ff object, or for pattern assignment only - a ffdf object

value

a new filename

...

dummy to keep R CMD CHECK quiet

Author

Jens Oehlschlägel

Details

Assigning a filename<- means renaming the corresponding file on disk - even for ram objects. If that fails, the assignment fails. If a file is moved in or out of getOption("fftempdir") the finalizer is changed accordingly to 'delete' in getOption("fftempdir") and 'close' otherwise.
A pattern is an incomplete filename (optional path and optional filename-prefix) that is turned to filenames by adding a random string using and optionally an extension from optionally an extension from getOption("ffextension") (see fftempfile). filename<- exhibits R's standard behaviour of considering "filename" and "./filename" both to be located in getwd. By constrast pattern<- will create "filename" without path in getOption("fftempdir") and only "./filename" in getwd.

See Also

fftempfile, finalizer, ff, as.ff, as.ram, update.ff, file.move

Examples

Run this code
  if (FALSE) {
  message("Neither giving pattern nor filename gives a random filename 
with extension ffextension in fftempdir")
  x <- ff(1:12)
  finalizer(x)
  filename(x)
  message("Giving a pattern with just a prefix moves to a random filename 
beginning with the prefix in fftempdir")
  pattern(x) <- "myprefix_"
  filename(x)
  message("Giving a pattern with a path and prefix moves to a random filename 
beginning with prefix in path (use . for getwd) ")
  pattern(x) <- "./myprefix"
  filename(x)
  message("Giving a filename moves to exactly this filename and extension 
in the R-expected place) ")
  if (!file.exists("./myfilename.myextension")){
    filename(x) <- "./myfilename.myextension"
    filename(x)
  }

  message("NOTE that the finalizer has changed from 'delete' to 'close': 
now WE are responsible for deleting the file - NOT the finalizer")
  finalizer(x)
  delete(x)
  rm(x)
  }

Run the code above in your browser using DataLab