tryBug: ~ Function: tryBug ~

Description Usage Arguments Details Value Examples

Description

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.

Usage

1

Arguments

...

A command

Details

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.

Value

None

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
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"))

packS4 documentation built on May 2, 2019, 9:25 a.m.