[R] Summary (Re: (S|odf)weave : how to intersperse (\LaTeX{}|odf) comments in source code ? Delayed R evaluation ?)

Claudia Beleites cbeleites at units.it
Mon Dec 13 11:31:42 CET 2010

Dear Emmanuel and dear list,
> Therefore, I let this problem to sleep. However, I Cc this answer (with
> the original question below) to Max Kuhn and Friedrich Leisch, in the
> (faint) hope that this feature, which does not seem to have been missed
> by anybody in 8 years,
I've been missing it every once in a while, but till now I could always rephrase
the problem with expand = FALSE or functions, and the chunk that does the actual
calculation at the end.

Most often, however, I'm just lazy and use R comments. If math should go in
there, I use listings instead of fancyvrb with the modified Sweave.sty that
hopefully is attached (if not, see below).

Here's an example chunk:
<<keep.source=TRUE>>=
1 / 2 # $\frac{1}{x}$
4 + 4 # Here may come lots of explanations, that are in a \LaTeX\
paragraph\footnote{blabla}: even long lines are properly broken.\\ Though the
new lines start at the beginning of the line. \\[6pt] And a line break in the
chunk source will of course be interpreted as R again: so no new paragraphs
inside the same comment.
# But there can be new commented lines.
3 + 6
# Note that comment only lines at the end of a code chunk seem to be lost.
# Not only one but all that aren't followed by R code
@
(the second line should be very long, I somehow can't keep thunderbird from
inserting line breaks)

Hope that helps a bit,

Claudia

=== modified Sweave.sty ===
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{Sweave}{}

\RequirePackage{ifthen}
\newboolean{Sweave at gin}
\setboolean{Sweave at gin}{true}
\newboolean{Sweave at ae}
\setboolean{Sweave at ae}{true}

\DeclareOption{nogin}{\setboolean{Sweave at gin}{false}}
\DeclareOption{noae}{\setboolean{Sweave at ae}{false}}
\ProcessOptions

\RequirePackage{graphicx,listings}
\IfFileExists{upquote.sty}{\RequirePackage{upquote}}{}

\ifthenelse{\boolean{Sweave at gin}}{\setkeys{Gin}{width=0.8\textwidth}}{}%
\ifthenelse{\boolean{Sweave at ae}}{%
\RequirePackage[T1]{fontenc}
\RequirePackage{ae}
}{}%

\lstnewenvironment{Sinput}{\lstset{language=R,basicstyle=\sl,texcl,
\lstnewenvironment{Soutput}{\lstset{language=R}}{}
\lstnewenvironment{Scode}{\lstset{language=R,basicstyle=\sl}}{}

\newenvironment{Schunk}{}{}

\newcommand{\Sconcordance}[1]{%
\ifx\pdfoutput\undefined%
\csname newcount\endcsname\pdfoutput\fi%
\ifcase\pdfoutput\special{#1}%
\else\immediate\pdfobj{#1}\fi}

--
Claudia Beleites
Dipartimento dei Materiali e delle Risorse Naturali
Università degli Studi di Trieste
Via Alfonso Valerio 6/a
I-34127 Trieste

phone: +39 0 40 5 58-37 68
email: cbeleites at units.it
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Sweave.sty
Type: text/x-tex
Size: 975 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20101213/602d7b0d/attachment.bin>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: test.Rnw
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20101213/602d7b0d/attachment.pl>