From phgrosjean at sciviews.org  Sun Oct 29 18:40:07 2006
From: phgrosjean at sciviews.org (Philippe Grosjean)
Date: Sun, 29 Oct 2006 18:40:07 +0100
Subject: [Rd] R GUI API: suggestion for R function to put in there?
In-Reply-To: <f8e6ff050610290828v28339862m7ef735bfca146cba@mail.gmail.com>
References: <4544DCDB.3060703@umh.ac.be>
	<f8e6ff050610290828v28339862m7ef735bfca146cba@mail.gmail.com>
Message-ID: <4544E777.8050502@sciviews.org>



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




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