checkFile: check file existence

View source: R/checkFile.R

checkFileR Documentation

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)

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

Value

TRUE/FALSE, invisibly

Author(s)

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

See Also

file.exists

Examples

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

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

## Not run: ## 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)

## End(Not run)

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)



berryFunctions documentation built on May 29, 2024, 4:01 a.m.