file-utilities {zooimage} | R Documentation |
These functions are usually not called directly by the user, but they are interesting for developers. They help to manage files in the context of ZooImage processes.
extensionPattern(extension = "r", add.dot = !grepl("[.]", extension))
hasExtension(file, extension = "r", pattern = extensionPattern(extension))
noExtension(file)
listFilesExt(dir, extension = "r", pattern = extensionPattern(extension), ... )
zimList(dir, ...)
zimDatList(dir, ...)
zipList(dir, ...)
zidList(dir, ...)
zidbList(dir, ...)
jpgList(dir, ...)
pngList(dir, ...)
checkFileExists(file, extension, message = "file not found: %s",
force.file = FALSE)
checkDirExists(dir, message = 'Path "%s" does not exist or is not a directory')
checkEmptyDir(dir, message = 'dir "%s" is not empty')
forceDirCreate(dir)
checkFirstLine(file, expected = c("ZI1", "ZI2", "ZI3", "ZI4", "ZI5"),
message = 'file "%s" is not a valid ZooImage version <= 5 file')
extension |
lowercase version of the extension (the pattern will be constructed to be case-insensitive). |
add.dot |
if a dot is not provided, it is added by default in front of the pattern. |
file |
one or more file names or file paths to check. |
pattern |
a pattern matching a given file extension. |
... |
further arguments passed to the function. Currently, not in use. |
dir |
the directory to work with. |
message |
a warning message to provide (file/dirname replacement using %s). |
force.file |
make sure the item is a file, not a directory. |
expected |
the expected content of the first line of the file. |
All these function issue only warnings, no errors. Those functions that
return TRUE
or FALSE
are designed to be used in batch mode.
A string with suitable pattern to match a file extension for
extensionPattern()
.
The function noExtension()
return base filenames without extensions.
A list of files with given extension for listFilesExt()
, and
xxxList()
functions.
The other functions return TRUE
or FALSE
, depending if the
tested condition is met or not.
Philippe Grosjean <Philippe.Grosjean@umons.ac.be>
# Construct a suitable pattern to match extensions of TIFF image files
extensionPattern("tif")
# Test if file names match given extensions (first 2 items only)
hasExtension(c("test1.tif", "test2.TIF", "test3.R"), "tif")
noExtension(c("test1.tif", "test2.TIF", "test3.R"))
# List all files with a given extension in a directory
ziDir <- system.file("examples", package = "zooimage")
listFilesExt(ziDir, "zid")
zidList(ziDir) # Idem
# Check that a file or a directory exists
checkDirExists(ziDir)
zisFile <- file.path(ziDir, "Description.zis")
checkFileExists(zisFile)
# Is this directory empty? (no)
checkEmptyDir(ziDir)
# force (re)creation of a directory
tmpDir <- file.path(tempdir(), "testdir")
forceDirCreate(tmpDir)
file.info(tmpDir)$isdir # yes
checkEmptyDir(tmpDir) # yes
file.remove(tmpDir)
file.exists(tmpDir)
# Every .zis file must start with ZI1-5 => check this...
checkFirstLine(zisFile)
# Clean up
rm(ziDir, zisFile, tmpDir)