Learn R Programming

berryFunctions (version 1.15.0)

checkFile: check file existance

Description

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

Usage

checkFile(file, warnonly = FALSE, trace = TRUE)

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 WARNING: in do.call settings with large objects, tracing may take a lot of computing time.

Value

TRUE/FALSE, invisibly

See Also

file.exists

Examples

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

## Not run: ------------------------------------
# ## Excluded from CRAN checks because of file creation
# # Vectorized:
# file.create("DummyFile2.txt")
# checkFile(paste0("DummyFile",1:3,".txt"), warnonly=TRUE)
# checkFile(paste0("DummyFile",1:3,".txt") )
# file.remove("DummyFile2.txt")
# 
# compareFiles("dummy.nonexist", "dummy2.nonexist")
# checkFile("dummy.nonexist")
## ---------------------------------------------

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