Learn R Programming

berryFunctions (version 1.11.0)

checkFile: check file existance

Description

check whether a file exists and give a useful error/warning/message

Usage

checkFile(file, fun = stop, trace = TRUE, ...)

Arguments

file
Filename(s) as character string to be checked for existence.
fun
One of the functions stop, warning, or message. DEFAULT: stop
trace
Logical: Add function call stack to the message? DEFAULT: TRUE
...
Further arguments passed to fun

Value

TRUE/FALSE, invisibly

See Also

file.exists

Examples

Run this code
is.error( checkFile("FileThatDoesntExist.txt") )
checkFile("FileThatDoesntExist.txt", fun=warning)
checkFile("FileThatDoesntExist.txt", fun=message)
is.error( checkFile("FileThatDoesntExist.txt", fun=MyWarn) ) # nonexisting function

## Not run: ## Excluded from CRAN checks because of file creation
# # Vectorized:
# file.create("DummyFile2.txt")
# checkFile(paste0("DummyFile",1:3,".txt"), fun=message)
# checkFile(paste0("DummyFile",1:3,".txt") )
# file.remove("DummyFile2.txt")
# ## End(Not run)

## Not run: ## Excluded from CRAN checks because of intentional errors
# compareFiles("dummy.nonexist", "dummy2.nonexist")
# checkFile("dummy.nonexist")
# 
# dingo <- function(k="brute.nonexist") checkFile(k)
# dingo()
# dingo("dummy.nonexist")
# 
# upper <- function(h) dingo(c(h, "dumbo.nonexist"))
# upper("dumbo2.nonexist")
# ## End(Not run)

Run the code above in your browser using DataLab