[Rd] R GUI API: suggestion for R function to put in there?

Philippe Grosjean phgrosjean at sciviews.org
Sun Oct 29 18:40:07 CET 2006



hadley wickham wrote:
>> - 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

Thanks, but... something is missing: what is the function o()? I don't 
find it elsewhere.
Best,

Philippe Grosjean




More information about the R-devel mailing list