checkStrings: Check if a variable which should contains strings values...

Description Usage Arguments Details Value Examples

View source: R/myBasicFunctions.R

Description

Check if a variable which should contains strings values exists and return values overlapping with the possible

Usage

1
checkStrings(variableS, possible = NA, default = NA, isRequired = T)

Arguments

variableS

a string containing the name of the variable to check.

possible

a vector containing the accepted string values or NA if there is no constrain. Default is NA.

default

the result if the variableS is not assigned or no value overlap with possible (if possible is not NA) and isRequired is set to FALSE. Default is NA.

isRequired

a logical value indicating if the function should stop in case no value overlap with possible (if possible is not NA). Default is TRUE.

Details

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

Value

The content of variableS if they are all included in possible (if possible is not NA) Or the overlap between its content and possible (if possible is not NA). Or the default value

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
myStrings <- c("one", "two", "three")

# No restriction
myCheckedStrings <- checkStrings("myStrings")

# Restriction which match
myCheckedStrings <- checkStrings("myStrings", possible = c("one", "two", "three", "four"))

# Restriction which match partially
myCheckedStrings <- checkStrings("myStrings", possible = c("one", "two"))

# Restriction which does not match
## Not run: 
myCheckedStrings <- checkStrings("myStrings", possible = c("One", "Two"))

## End(Not run)

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

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