checkFile: Check if a variable which should contains a path for a file...

Description Usage Arguments Details Value Examples

View source: R/myBasicFunctions.R

Description

Check if a variable which should contains a path for a file exists and has a value which corresponds to an existing file

Usage

1
checkFile(variableFile, default = NA, isRequired = T)

Arguments

variableFile

a string containing the name of the variable to check

default

the result if the variableFile is not assigned or the file does not exists and isRequired is set to FALSE, default is NA

isRequired

a logical value indicating if the function should stop in case the file does not exists, default is TRUE

Details

If isRequired is set to TRUE and the content of variableFile is not valid, it will stop and execute an error.

Value

The content of variableFile if it is the path to an existing file or the default value

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# A file which exists:
myFile <- ".Rhistory"
myFile <- list.files()[1]
myCheckedFile <- checkFile("myFile")

# A variable which does not exists:
myCheckedFile <- checkFile("myImaginaryVariableWhichShouldNotExists",isRequired=FALSE)

# A variable which does not exists but with default:
myCheckedFile <- checkFile("myImaginaryVariableWhichShouldNotExists",
                           default=".Rhistory", isRequired=FALSE)

# A variable which does not exists but is required:
## Not run: 
myCheckedFile <- checkFile("myImaginaryVariableWhichShouldNotExists")

## End(Not run)

lldelisle/usefulLDfunctions documentation built on Nov. 29, 2021, 5:40 a.m.