Learn R Programming

berryFunctions (version 1.22.5)

checkFile: check file existence

Description

check whether files exist and give a useful error/warning/message

Usage

checkFile(file, warnonly = FALSE, trace = TRUE, pwd = TRUE, nprint = 2)

Value

TRUE/FALSE, invisibly

Arguments

file

Filename(s) as character string to be checked for existence.

warnonly

Logical: Only issue a warning instead of an error with stop? DEFAULT: FALSE

trace

Logical: Add function call stack to the message? DEFAULT: TRUE

pwd

Logical: Print working directory in message? DEFAULT: TRUE

nprint

Integer: number of filenames to be printed. The rest is abbreviated with (and n others). DEFAULT: 2

Author

Berry Boessenkool, berry-b@gmx.de, May 2016

See Also

Examples

Run this code
is.error( checkFile("FileThatDoesntExist.txt")  )
checkFile("FileThatDoesntExist.txt", warnonly=TRUE)
checkFile("FileThatDoesntExist.txt", warnonly=TRUE, trace=FALSE)

checkFile("./", warnonly=TRUE)
checkFile(c("./",".//"), warnonly=TRUE)

if (FALSE) ## Excluded from CRAN checks because of file creation
# Vectorized:
file.create("DummyFile2.txt")
checkFile("DummyFile2.txt/")
checkFile(paste0("DummyFile",1:3,".txt"), warnonly=TRUE)
is.error(checkFile(paste0("DummyFile",1:3,".txt") ), TRUE, TRUE)
file.remove("DummyFile2.txt")

is.error(compareFiles("dummy.nonexist", "dummy2.nonexist"), TRUE, TRUE)
is.error(checkFile("dummy.nonexist"), TRUE, TRUE)


dingo <- function(k="brute.nonexist", trace=TRUE)
         checkFile(k, warnonly=TRUE, trace=trace)
dingo()
dingo("dummy.nonexist")

upper <- function(h, ...) dingo(c(h, "dumbo.nonexist"), ...)
upper("dumbo2.nonexist")
upper(paste0("dumbo",2:8,".nonexist"))
upper(paste0("dumbo",2:8,".nonexist"), trace=FALSE)


Run the code above in your browser using DataLab