checkLogicalValue: Check if a variable which should contains a logical value...

Description Usage Arguments Details Value Examples

View source: R/myBasicFunctions.R

Description

Check if a variable which should contains a logical value exists and its content is logical

Usage

1
checkLogicalValue(variableL, default = NA, isRequired = T)

Arguments

variableL

a string containing the name of the variable to check

default

the result if the variableL is not assigned or the content are not logical and isRequired is set to FALSE, default is NA

isRequired

a logical value indicating if the function should stop in case the values are not numeric, default is TRUE

Details

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

Value

The first value contained in variableL if it is logical or the default value

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# the content is logical:
myLogicalValue <- TRUE
myCheckedLogicalValue <- checkLogicalValue("myLogicalValue")

myLogicalValue <- NA
myCheckedLogicalValue <- checkLogicalValue("myLogicalValue")

# my value is not logical:
myLogicalValue <- "T"
## Not run: 
myCheckedLogicalValue <- checkLogicalValue("myLogicalValue")

## End(Not run)

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

# A variable which does not exists but with default:
myCheckedLogicalValue <- checkLogicalValue("myImaginaryVariableWhichShouldNotExists",
                                           default = TRUE, isRequired = FALSE)

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

## End(Not run)

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