Hi,

I'm writing a manual using Sweave and I want to be able to print errors from
bad code. Here's an example:

<Function-4a>>=
MySqrt <- function(x) {
  if (missing(x)) {
    stop("'x' is missing with no default")
  }
  if (!is.numeric(x)) {
    stop("'x' should only be numeric")
  }
  if (x < 0) {
    stop("'x' should be non-negative")
  }
  return(sqrt(x))
}
MySqrt()
MySqrt("a")
MySqrt(-2)
MySqrt(4)
@

And I would like the output to be:

MySqrt <- function(x) {
...
}
> MySqrt()
Error in MySqrt() : 'x' is missing with no default
> MySqrt("a")
Error in MySqrt("a") : 'x' should only be numeric
> MySqrt(-2)
Error in MySqrt(-2) : 'x' should be non-negative
> MySqrt(2)
[1] 1.414214

I.e. I want the Error statements to print in the tex file and not just make
Sweave to bomb.

Thanks,

--sundar

	[[alternative HTML version deleted]]

