带前导字符的针织/编织格式代码输出

带前导字符的针织/编织格式代码输出

使用 knitr/sweave,我需要根据编辑期刊的要求来格式化回显的 R 代码输出。

例如,以下块

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

格式如下:

> library(plyr)

不过,我希望它的格式如下:

R> library(plyr)

我该如何修改前导 V 形纹?


Sweave 格式通过以下块使用:

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

我正在使用以下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}

答案1

弄清楚了,需要设置 R 会话中使用的选项:

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

相关内容