使用bioconductor的BiocStyle书写package vignettes

Bioconductor core推出了BiocStyle软件包,很快这一规范会应用至大多数的bioconductor的软件包。

vignettes文件就很好地示例了如何使用及其显示结果。

BiocStyle提供了一些很好的宏,这其中就包括在Rd文件中常常使用到的\Rpackage, \Rfunction等。BiocStyle还为插入图象提供了很好的支持,我们只需要使用

<<chunk_tag,fig=TRUE,include=FALSE>>=
##codes here
@
\incfig{packageName-chunk_tag}{\textwidth}{Title}{discriptions}

的格式就可以实现Rnw中实时运行代码及为插入的图片指明尺寸及图例。而且这种方式插入不会多次运行绘图代码,使得翻译的速度会更快。在需要交差引用图片的位置,我们使用\ref{packageName-chunk_tag}形式就可以了。
\incfig后跟着四个大括号,其中分别是图片的名称,插入图形的宽度,图例中黑体字的名称,以及图例中具体的描述。
需要注意的是,一段代码只插入一个图片。

使用BiocStyle,首先要做两件事,第一,在DESCRIPTION文件中的Suggests中加入BiocStyle,如

Suggests: BiocStyle

然后在Rnw文件头的部分,(具体是在\begin{document}之前。一般大家会插入在\documentclass之后,\usepackage之前),插入如下的内容:

<<style, echo=FALSE, results=tex>>=
BiocStyle::latex()
@

有了BiocStyle之后,内容中的@符号需要使用其它的字符来替换表示。

我们就来看看其示例的原代码

%% \VignetteIndexEntry{Bioconductor LaTeX Style}
 
\documentclass{article}
 
<<style, echo=FALSE, results=tex>>=
BiocStyle::latex()
@ 
 
\title{\Bioconductor{} \LaTeX{} Style}
\author{Martin Morgan, Andrzej Ole\'s, Wolfgang Huber}
 
\begin{document}
 
\maketitle
 
\tableofcontents
 
\section{Use}
 
Add the following to your package \texttt{DESCRIPTION}:
\begin{verbatim}
    Suggests: BiocStyle
\end{verbatim}
Add this code chunk to the preamble of each vignette:
\begin{verbatim}
    <<style, eval=TRUE, echo=FALSE, results=tex>>=
    BiocStyle::latex()
    @ 
\end{verbatim}
Arguments to \Rfunction{latex} are passed to \Rcode{options}; the
default sets \Rcode{width=90}.
 
\section{Mark-up}
 
Software:
\begin{itemize}
\item \verb+\R{}+ and \verb+\Bioconductor{}+ to reference \R{}
  software and the \Bioconductor{} project.
\item \verb+\software{GATK}+ to reference third-party software, e.g.,
  \software{GATK}.
\end{itemize}
%% 
Packages:
\begin{itemize}
\item \verb+\Biocpkg{IRanges}+ for \Bioconductor{} software packages, including
  a link to the release version landing page, \Biocpkg{IRanges}.
\item \verb+\Biocannopkg{org.Hs.eg.db}+ for \Bioconductor{} annotation
  packages, including a link to the release version landing page,
  \Biocannopkg{org.Hs.eg.db}.
\item \verb+\Biocexptpkg{parathyroidSE}+ for \Bioconductor{}
  experiment data packages, including a link to the release version
  landing page, \Biocexptpkg{parathyroidSE}.
\item \verb+\Rpkg{data.table}+ for \R{} packages available on CRAN,
  including a link to the FHCRC CRAN mirror landing page,
  \Rpkg{data.table}.
\item \verb+\Rpackage{MyPkg}+ for \R{} packages that are \emph{not}
  available on \Bioconductor{} or CRAN.
\end{itemize}
%% 
Code:
\begin{itemize}
\item \verb+\Rfunction{findOverlaps}+ for functions
  \Rfunction{findOverlaps}.
\item \verb+\Robject{olaps}+ for variables \Robject{olaps}.
\item \verb+\Rclass{GRanges}+ when refering to a formal class
  \Rclass{GRanges}.
\end{itemize}
%% 
Communication:
\begin{itemize}
\item \verb+\comment{comment to the user}+ communicates a
  \comment{comment to the user}.
\item \verb+\warning{common pitfalls}+ signals \warning{common
    pitfalls}.
\item \verb+\fixme{incomplete functionality}+ provides an indication
  of \fixme{incomplete functionality}.
\end{itemize}
%% 
 
%---------------------------------------------------------
\section{Sectioning: this is a section}
%---------------------------------------------------------
 
Use \verb+\tableofcontents+ for a hyperlinked table of contents,
\verb+\section+, \verb+\subsection+, \verb+\subsubsection+ for structuring your vignette.
 
\subsection{This is a subsection}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
 
\subsubsection{This is a subsubsection}
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
 
%---------------------------------------------------------
\section{Including a figure}
%---------------------------------------------------------
 
Besides the usual \LaTeX{} capabilities (\verb+figure+ environment and
\verb+includegraphics+ command), \texttt{Bioconductor.sty} defines a
shortcut \verb+\incfig{filename}{width}{shorttitle}{extendedcaption}+,
which expects four arguments:
\begin{description}
\item[filename] The name of the figure file, also used as the label by
  which the float can be refered to by \verb+\ref{}+.
\item[width] Figure width.
\item[shorttitle] A short description, used in the list of figures and
  printed in bold as the first part of the caption.
\item[extendedcaption] Continuation of the figure caption.
\end{description}
Thus
\begin{verbatim}
    <<figureexample,fig=TRUE,include=FALSE,width=4.2,height=4.6>>=
    v = seq(0, 60i, length=1000)
    plot(abs(v)*exp(v), type="l", col="Royalblue")
    @ 
    \incfig{LatexStyle-figureexample}{0.25\textwidth}{A curve.}
        {The code that creates this figure is shown in the code chunk.}
    as shown in Figure~\ref{LatexStyle-figureexample}.
\end{verbatim}
results in 
<<figureexample,fig=TRUE,include=FALSE,width=4.2,height=4.6>>=
v = seq(0, 60i, length=1000)
plot(abs(v)*exp(v), type="l", col="Royalblue")
@ 
%% 
\incfig{LatexStyle-figureexample}{0.25\textwidth}{A curve.}{The code
  that creates this figure is shown in the code chunk.}
as shown in Figure~\ref{LatexStyle-figureexample}.
 
%---------------------------------------------------------
\section{Session info}
%---------------------------------------------------------
Here is the output of \Rfunction{sessionInfo} on the system on which
this document was compiled:
<<sessionInfo, results=tex, print=TRUE>>=
toLatex(sessionInfo())
@
 
\end{document}

Leave a Reply

  

  

  

%d 博主赞过: