Learn R Programming

reader (version 1.1.0)

is.file: Test whether a file exists in a target directory, or alternative list of directories.

Description

Looks for a file named 'fn' in 'dir', and if not found there, broadens the search to the list or vector of directorys, 'dirs'. Returns TRUE or FALSE as to whether the file exists.

Usage

is.file(fn, dir = "", dirs = NULL, combine = TRUE)

Value

logical vector of whether each file was found, or if combine is true, then a single value whether ALL valid or not.

Arguments

fn

name of the file to search for

dir

the first directory to look in (expected location)

dirs

vector/list, a set of directories to look in should the file not be found in 'dir'.

combine

if a list is given, test whether ALL files valid

Author

Nicholas Cooper nick.cooper@cimr.cam.ac.uk

See Also

find.file

Examples

Run this code
orig.dir <- getwd(); setwd(tempdir()); # move to temporary dir
l.fn <- "temp.txt"
writeLines("test",con=l.fn)
some.local.files <- narm(list.files()[1:10])
print(some.local.files)
is.file(l.fn)
is.file(l.fn,dir=getwd())
is.file(some.local.files)
# add a non-valid file to the list to see what happens
is.file(c(some.local.files,"fakefile.unreal"))
is.file(c(some.local.files,"fakefile.unreal"),combine=FALSE)
unlink(l.fn)
setwd(orig.dir) # reset working dir to original

Run the code above in your browser using DataLab