Learn R Programming

packS4 (version 0.9.3)

tryBug: ~ Function: tryBug ~

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

tryBug(...)

Arguments

...
A command

Value

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.

Examples

Run this code
### 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"))

Run the code above in your browser using DataLab