> - To execute R code contained in a string and return the result of this
> evaluation in a string (including presentation of error messages and
> warnings) exactly as if this was entered at the prompt. Duncan Murdoch
> is against such a kind of function (he says a GUI should not substitute
> to the R interpreter, and it should manage and present errors or
> warnings in a better way than the teletype approach of the command

This is useful for useful for things like Sweave.  I have a modified
version of capture.output that captures everything:

capture.all <- function(code, envir = globalenv()) {
        printErrors <- function(code) {
                tryCatch(
                        eval(parse(text=code), envir = envir),
                        error = function(e) o(e)
                )
        }

        paste(capture.output(
          withCallingHandlers(printErrors(code), warning = function(x) {
                cat("Warning: ", x$message, "\n")
                invokeRestart("muffleWarning")
        })), collapse="\n", sep="")
}

for my (unreleased) sweave-like package.  It's not perfect, but it has
served my needs.

Hadley

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to