This function allows tesing if a given file-name corresponds to an existing file (eg for reading lateron). Indications to the path and file-extensions may be given separately. If no files do match .gz compressed versions may be searched, too.
checkFilePath(
fileName = NULL,
path = "./",
expectExt = "",
mode = "compressedOption",
compressedOption = NULL,
strictExtension = NULL,
stopIfNothing = NULL,
silent = FALSE,
debug = FALSE,
callFrom = NULL
)This function returns a character vector with verified file-name(s) (and path), returns NULL if nothing found - unless mode="stopIfNothing"
(character) name of file to be tested; may also include an absolute or relative path;
if NULL and path as well as expectExt will take 1st file in given path and proper extension
(character, length=1) optional separate entry for path of fileName
(character) file extension (will not be considered if "")
(character) further details if function should give error or warning if no files found
integrates previous argument compressedOption to also look for look for .gz compressed files;
strictExtension to decide if extension (expectExt) - if given - should be considered obligatory;
stopIfNothing to stop with error if no files found
deprected (logical) also look for .gz compressed files
deprected (logical) decide if extesion (expectExt) - if given - should be considered obligatory
deprected, please use argument mode instead !
(logical) suppress messages
(logical) additional messages for debugging
(character) allow easier tracking of messages produced
When the filename given by the user exists but it's file-extension is not matching expectExt
the argument strictExtension allows to decide if the filename will still be returned or not.
When expectExt is given, initial search will look for perfect matches.
However, if nothing is found and strictExtension=FALSE, a more relaxed and non-case-sensitive search will be performed.
(RhomeFi <- list.files(R.home()))
file.exists(file.path(R.home(), "bin"))
checkFilePath(c("xxx","unins000"), R.home(), expectExt="dat")
Run the code above in your browser using DataLab