[R] Sweave : allowing errors in R code?

Remko Duursma remkoduursma at gmail.com
Tue Aug 9 11:54:56 CEST 2011




Thanks Duncan. 
I ended up resorting to <<eval=FALSE>>, and just adding the error
message 'manually', which is what the Schunk approach does as well. 

Unfortunately, the highlight package does not work with that Schunk -
because it replace the Sweave driver, but anyway, this is close enough.

On this:
> If not, another alternative is to use a combination of 
> chunks with eval=false at first to be displayed, then with try() and 
> echo=false to do the actual calculation and display of the error.

But with echo=FALSE, the error is not displayed ... 

remko

> It is not very easy to display errors in Sweave.  I think there are 
> intentions to provide more support, but for now it's not there.

> The way I've done it is like this:

> \begin{Schunk}
> \begin{Sinput}
 > > t(Y) + X
> \end{Sinput}
\begin{Soutput}
Error in t(Y) + X : non-conformable arrays
\end{Soutput}
\end{Schunk}

This is similar to what Sweave would have produced if it displayed 
errors without stopping, so it might work properly with your syntax 
highlighting.  If not, another alternative is to use a combination of 
chunks with eval=false at first to be displayed, then with try() and 
echo=false to do the actual calculation and display of the error.

Duncan Murdoch

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


On 11-08-08 9:48 PM, Remko Duursma wrote:
> Dear R-helpers,
>
>
> sorry if this is obvious, but I can't find this in the documentation.
>
> I am using Sweave, and have some code that does not actually work - but I
> want to include it anyway, including the error message that R produces.
>
> But on running Sweave() on my .Rnw file, it simply halts when it gets to
> the
> code chunk with the bad code.
>
> I can use \verbatim{} instead, but then I don't get R's output
> automatically
> (nor do I get the nice syntax highlighting from the highlight package that
> I
> am using).

It is not very easy to display errors in Sweave.  I think there are 
intentions to provide more support, but for now it's not there.

The way I've done it is like this:

\begin{Schunk}
\begin{Sinput}
 > t(Y) + X
\end{Sinput}
\begin{Soutput}
Error in t(Y) + X : non-conformable arrays
\end{Soutput}
\end{Schunk}

This is similar to what Sweave would have produced if it displayed 
errors without stopping, so it might work properly with your syntax 
highlighting.  If not, another alternative is to use a combination of 
chunks with eval=false at first to be displayed, then with try() and 
echo=false to do the actual calculation and display of the error.

Duncan Murdoch

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


On 11-08-08 9:48 PM, Remko Duursma wrote:
> Dear R-helpers,
>
>
> sorry if this is obvious, but I can't find this in the documentation.
>
> I am using Sweave, and have some code that does not actually work - but I
> want to include it anyway, including the error message that R produces.
>
> But on running Sweave() on my .Rnw file, it simply halts when it gets to
> the
> code chunk with the bad code.
>
> I can use \verbatim{} instead, but then I don't get R's output
> automatically
> (nor do I get the nice syntax highlighting from the highlight package that
> I
> am using).

It is not very easy to display errors in Sweave.  I think there are 
intentions to provide more support, but for now it's not there.

The way I've done it is like this:

\begin{Schunk}
\begin{Sinput}
 > t(Y) + X
\end{Sinput}
\begin{Soutput}
Error in t(Y) + X : non-conformable arrays
\end{Soutput}
\end{Schunk}

This is similar to what Sweave would have produced if it displayed 
errors without stopping, so it might work properly with your syntax 
highlighting.  If not, another alternative is to use a combination of 
chunks with eval=false at first to be displayed, then with try() and 
echo=false to do the actual calculation and display of the error.

Duncan Murdoch

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


On 11-08-08 9:48 PM, Remko Duursma wrote:
> Dear R-helpers,
>
>
> sorry if this is obvious, but I can't find this in the documentation.
>
> I am using Sweave, and have some code that does not actually work - but I
> want to include it anyway, including the error message that R produces.
>
> But on running Sweave() on my .Rnw file, it simply halts when it gets to
> the
> code chunk with the bad code.
>
> I can use \verbatim{} instead, but then I don't get R's output
> automatically
> (nor do I get the nice syntax highlighting from the highlight package that
> I
> am using).

It is not very easy to display errors in Sweave.  I think there are 
intentions to provide more support, but for now it's not there.

The way I've done it is like this:

\begin{Schunk}
\begin{Sinput}
 > t(Y) + X
\end{Sinput}
\begin{Soutput}
Error in t(Y) + X : non-conformable arrays
\end{Soutput}
\end{Schunk}

This is similar to what Sweave would have produced if it displayed 
errors without stopping, so it might work properly with your syntax 
highlighting.  If not, another alternative is to use a combination of 
chunks with eval=false at first to be displayed, then with try() and 
echo=false to do the actual calculation and display of the error.

Duncan Murdoch

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


On 11-08-08 9:48 PM, Remko Duursma wrote:
> Dear R-helpers,
>
>
> sorry if this is obvious, but I can't find this in the documentation.
>
> I am using Sweave, and have some code that does not actually work - but I
> want to include it anyway, including the error message that R produces.
>
> But on running Sweave() on my .Rnw file, it simply halts when it gets to
> the
> code chunk with the bad code.
>
> I can use \verbatim{} instead, but then I don't get R's output
> automatically
> (nor do I get the nice syntax highlighting from the highlight package that
> I
> am using).

It is not very easy to display errors in Sweave.  I think there are 
intentions to provide more support, but for now it's not there.

The way I've done it is like this:

\begin{Schunk}
\begin{Sinput}
 > t(Y) + X
\end{Sinput}
\begin{Soutput}
Error in t(Y) + X : non-conformable arrays
\end{Soutput}
\end{Schunk}

This is similar to what Sweave would have produced if it displayed 
errors without stopping, so it might work properly with your syntax 
highlighting.  If not, another alternative is to use a combination of 
chunks with eval=false at first to be displayed, then with try() and 
echo=false to do the actual calculation and display of the error.

Duncan Murdoch

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



--
View this message in context: http://r.789695.n4.nabble.com/Sweave-allowing-errors-in-R-code-tp3728790p3729480.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list