%%% RweaveExtra: Sweave drivers with extra tricks up their sleeve
%%%
%%% Copyright (C) 2021-2024 Vincent Goulet
%%% License: GPL 2 or later

\documentclass{article}
  \usepackage{Sweave}
  %\SweaveUTF8

  \title{RweaveExtra weaving and tangling examples}
  \author{Vincent Goulet}

  \newcommand{\code}[1]{\texttt{#1}}
  \newcommand{\pkg}[1]{\textbf{#1}}

\begin{document}

The purpose of this document is not to demonstrate usage of Sweave,
but rather only of the additional options provided by the
\pkg{RweaveExtra} package.

The following code chunk is processed normally by Sweave as well as by
Stangle. Its content must be parsable by R.
<<echo=TRUE>>=
1:10
@

We remove the chunk separator before this next chunk. Therefore, it
will appear immediately after the previous one in the tangled script.
<<echo=TRUE, chunk.sep=FALSE>>=
runif(10)
@

The next chunk contains a deliberate error --- say for didactic
purposes. We can avoid an error with Sweave by using the option
\code{eval=FALSE}, but then the chunk is commented out in the
tangled script.
<<echo=TRUE, eval=FALSE>>=
2 + does.not.exist
@

With option \code{weave=FALSE} (or \code{ignore.on.weave=TRUE})
provided by the \code{RweaveExtraLatex} driver, the chunk is neither
parsed nor evaluated by Sweave. Therefore, we can even include code
not parsable by R in the chunk. However, the code is processed as
usual by Stangle, that is, without being commented out.
<<echo=TRUE, weave=FALSE>>=
2 a
@

Paired with option \code{extension}, this is also useful to keep, in a
single source file, R code as well as code in another programming
language. The former must be evaluated, but not the latter.
<<hello, extension=sh, prefix=FALSE, weave=FALSE>>=
#!/bin/sh

echo "Hello, World!"

exit 0
@

Finally, we have a chunk that is processed normally by Sweave, but
that is ignored by Stangle. This is convenient with \code{split =
  TRUE} to avoid littering the output directory with unimportant
scripts.
<<echo=TRUE, tangle=FALSE>>=
rnorm(10)
@

\end{document}
