extract_files: Extract files matching a pattern

Description Usage Arguments Value Examples

Description

Extracts files matching a pattern from a directory, copying and/or removing duplicate files (based on a user-supplied function) if specified. If a destination directory is specified, files will be copied (and not overwritten, even if filenames are identical).

Usage

1
2
extract_files(source_dir, pattern, destination_dir = NULL,
  remove_duplicates = FALSE, unique_fun = NULL, verbose = TRUE)

Arguments

source_dir

the directory to look for the files

pattern

the pattern of files (NULL for all files) to extract

destination_dir

the directory to which files will be copied (NULL if files should not be copied)

remove_duplicates

TRUE if duplicate files (based on the function supplied in unique_fun) should be removed from the list (they will not be deleted). If destination_dir is specified, the duplicate files will not be copied. If a file to be copied already exists in destination_dir (as determined by unique_fun), the file will not be copied but the name of the existing file will be included in the list of files returned.

unique_fun

the function that will return a unique value for unique files. the most reliable is probably tools::md5sum() (the default), but for large files this is slow and file.size() may be adequate. In some cases basename() may also be sufficient.

verbose

TRUE if status messages should be printed.

Value

A list of file paths. If destination_dir is specified, the list of file paths will be to the copied files. If not, the list of file paths will be relative to the working directory.

Examples

1
extract_files(getwd(), "*.*", remove_duplicates=TRUE)

paleolimbot/rfuncs documentation built on May 24, 2019, 6:13 p.m.