2

Using knitr/sweave, I need to format the R code output that gets echoed, according to editorial journal requirements.

For example, the following chunk

<<example,echo=TRUE>>=
library(plyr)
@

Is formatted as follows:

> library(plyr)

However, I would like it to be formatted like this:

R> library(plyr)

How can I modify the leading chevron?


Sweave format is being used via the following chunk:

%Read the Script into File
<<setup,echo=FALSE,eval=TRUE>>=
    render_sweave()
@

I am using the following sweave.sty

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{Sweave}{}

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

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

\RequirePackage{graphicx,fancyvrb,textcomp}
%% inspired by an earlier version of upquote.sty
\begingroup
\catcode`'=\active \catcode``=\active
\g@addto@macro\@noligs{\let`\textasciigrave \let'\textquotesingle}
\endgroup

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

\DefineVerbatimEnvironment{Sinput}{Verbatim}{fontshape=sl}
\DefineVerbatimEnvironment{Soutput}{Verbatim}{}
\DefineVerbatimEnvironment{Scode}{Verbatim}{fontshape=sl}

\ifdefined\Schunk%
  \message{\string Environment Schunk is already defined, stay with former definition}%
\else
  \newenvironment{Schunk}{}{}%
\fi

\newcommand{\Sconcordance}[1]{%
  \ifx\pdfoutput\undefined%
  \csname newcount\endcsname\pdfoutput\fi%
  \ifcase\pdfoutput\special{#1}%
  \else%
   \begingroup%
     \pdfcompresslevel=0%
     \immediate\pdfobj stream{#1}%
     \pdfcatalog{/SweaveConcordance \the\pdflastobj\space 0 R}%
   \endgroup%
  \fi}
2

Figured it out, need to set the options used in the R session:

<<customOptions,echo=FALSE,eval=TRUE>>=
    options(prompt   = "R> ",
            continue = "+    ")
@

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.