find.file: Search for a directory to add to the path so that a file...

Description Usage Arguments Value Author(s) See Also Examples

View source: R/reader.R

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 the full path of the first match that exists.

Usage

1
find.file(fn, dir = "", dirs = NULL)

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'.

Value

if the file is found, returns the full path of the file, else returns an empty string ""

Author(s)

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

See Also

is.file

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
orig.dir <- getwd(); setwd(tempdir()); # move to temporary dir
l.fn <- "temp.txt"
writeLines("test",con=l.fn)
find.file(l.fn)
find.file(l.fn,dir=getwd())
unlink(l.fn)
# not run # common.places <- ## <<add local folder here>> ##
# not run # d.fn <- cat.path(common.places[1],l.fn)
# write this example file to the first of the folders #
# not run # if(!file.exists(d.fn)) {  writeLines("test2",con=d.fn) }
# search the local folders for a
# a file named 'temp.txt'
# not run # find.file(l.fn,dir=getwd(),dirs=common.places)
# unlink(d.fn) # run only if test file produced
setwd(orig.dir) # reset working dir to original

reader documentation built on May 2, 2019, 9:27 a.m.