Description Usage Details Value Examples
Validate input and run calling method. Template to structure and test larger methods.
1 |
First validate
is called. If any errors are added, the value of invalid_result
is returned,
else the value of result
.
Loads the following methods into the environment of the calling method:
add_error(key, value)
errors()
#returns list(key=value, key2=value2)
validate_and_runner()
# Used internally, contains the logic of functions to call.
If any errors are added, the value of invalid_result
is returned,
else the value of result
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | two_times_two <- function(two, also_two) {
result <- function() helper()
helper <- function() two * also_two
validate <- function() {
if(two != 2) add_error('two', 'should be 2')
if(also_two != 2) add_error('also_two', 'should also be two')
}
invalid_result <- function() {
list(result=NA, errors=errors())
}
ShadowCAT:::validate_and_run()
}
# No errors
two_times_two(2,2)
# Error
two_times_two(3,2)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.