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{swe...@gin}
\setboolean{swe...@gin}{true}
\newboolean{swe...@ae}
\setboolean{swe...@ae}{true}

\declareoption{nogin}{\setboolean{swe...@gin}{false}}
\declareoption{noae}{\setboolean{swe...@ae}{false}}
\ProcessOptions

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

\ifthenelse{\boolean{swe...@gin}}{\setkeys{gin}{width=0.8\textwidth}}{}%
\ifthenelse{\boolean{swe...@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}


--
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: cbelei...@units.it
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{Sweave}{}

\RequirePackage{ifthen}
\newboolean{swe...@gin}
\setboolean{swe...@gin}{true}
\newboolean{swe...@ae}
\setboolean{swe...@ae}{true}

\declareoption{nogin}{\setboolean{swe...@gin}{false}}
\declareoption{noae}{\setboolean{swe...@ae}{false}}
\ProcessOptions

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

\ifthenelse{\boolean{swe...@gin}}{\setkeys{gin}{width=0.8\textwidth}}{}%
\ifthenelse{\boolean{swe...@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}
\documentclass{article}
\begin{document}
<<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
@
\end{document}

______________________________________________
R-help@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.

Reply via email to