Skip to content
Prev 244716 / 398506 Next

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

Dear Emmanuel and dear list,
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, 
commentstyle=\upshape}}{}
\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}