checkNumericalValues: Check if a variable which should contains numerical values...

Description Usage Arguments Details Value Examples

View source: R/myBasicFunctions.R

Description

Check if a variable which should contains numerical values exists and all values are numeric

Usage

1
checkNumericalValues(variableN, default = NA, isRequired = T)

Arguments

variableN

a string containing the name of the variable to check

default

the result if the variableN is not assigned or some values are not numeric 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 variableN is not valid, it will stop and execute an error.

Value

The content of variableN if they are all numeric 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
# all values are numeric:
myNumbers <- 1:3
myCheckedNumbers <- checkNumericalValues("myNumbers")

# some values are not numeric:
## Not run: 
myNumbers <- list(1,2,"T")
myCheckedNumbers <- checkNumericalValues("myNumbers")

## End(Not run)

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

# A variable which does not exists but with default:
myCheckedNumbers <- checkNumericalValues("myImaginaryVariableWhichShouldNotExists",
                                          default = c(1,2,12), isRequired = FALSE)

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

## End(Not run)

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