6 Evaluation modes
Package wyz.code.offensiveProgramming comes with several evaluation modes. Evaluation modes allow you to set up a particular execution context according to our needs. This allows to run R function under the given evaluation context, and to get back an evaluation mode compliance analysis result.
You may retrieve evaluation modes by using function defineEvaluationModes that returns the 3 following modes
print(defineEvaluationModes())
#> [1] "standard_R_evaluation" "enhanced_R_evaluation"
#> [3] "type_checking_enforcement"
6.1 Understanding evaluation modes
The first mode, standard_R_evaluation, is to ease comparisons with standard R evaluation. It does not make any sense to use only this mode when using wyz.code.offensiveProgramming.
The second mode, enhanced_R_evaluation, goes further than standard R evaluation, as it implies a function return type verification. This mode will check your function returns values in accordance with the declared returned type. This mode let you add to R a way to declared expected return type for a function.
The third mode, type_checking_enforcement, goes still further than the second mode, as it implies a function parameter types verification. This mode will check that each parameter provided to the function will match its semantic name defined type. This mode mimics a compiler output for R but it still interpreted language.
6.2 Instantiating evaluation mode
To handle evaluation mode, use function EvaluationMode. A typical way to do so is
em <- EvaluationMode(defineEvaluationModes()[3])
# convenient definitions, I will reuse in the coming book chapters to simplify writing
emo <- list(
standard = EvaluationMode(defineEvaluationModes()[1]),
enhanced = EvaluationMode(defineEvaluationModes()[2]),
type = EvaluationMode(defineEvaluationModes()[3])
)