Description Usage Arguments Details Value Examples
This function "try" to run its argement (like the function try
). If the evaluated argument is not correct, then everything is fine. If the argument is correct, then tryBug stop the execution.
1 |
... |
A command |
This function "try" to run its argement (like the function try
). If the evaluated argument is not correct, then everything is fine. If the argument is correct, then tryBug stop the execution.
This is usefull in the programme tests file: in some case, on some specific argument, a function should not work, and if it does work, then there is a bug. The tryBug function will detect this kind of bug.
None
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 28 29 30 31 | ### A function...
f <- function(oldYoung){
if(oldYoung=="old"){
cat("You are not that old!")
}else{
cat("You are young, great for you!")
}
}
### ... that we test
# f("old") # ok
# f("young") # ok
# tryBug(f("dead")) #not ok
### The corrected function...
f <- function(oldYoung){
if(oldYoung=="old"){
cat("You are not that old!")
}else{
if(oldYoung=="young"){
cat("You are young, great for you!")
}else{
stop("We deal only with young and old peoples!")
}
}
}
### ... with its new tests.
f("old")
f("young")
tryBug(f("dead"))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.