KnitR,Latex条件显示文本和代码块

时间:2014-05-02 22:26:17

标签: r latex knitr pdflatex

如何根据某些条件打开/关闭特定部分的显示? 例如,我想仅在xyplotFacSpecTotVarTest.pdf存在时才显示以下子部分。

我该怎么做?

\subsection{Checksum: Factor, Specific, and Total Variance}
Perhaps the most basic test of a regression model is if the factor and specific variances sum to equal the total variance.  Here, we 
present this diagnostic as an xy-plot, with the sum of factor and specific variance on the x-axis and the total variance on the y-axis.  We 
expect the plotted points to line up tightly along the identity line.

\clearpage
\begin{figure}[!h]

\centering

\includegraphics{\Sexpr{image_dir}xyplotFacSpecTotVarTest.pdf}

\caption{Total Variance vs. Sum of Factor and Specific Variance, All Instruments Passing Exposure Model.}

\end{figure}

1 个答案:

答案 0 :(得分:6)

将您的子部分放在另一个文件中,例如sub.Rnw。然后有条件地将它包含在主文档中,例如

<<child = if (file.exists('foo.pdf')) 'sub.Rnw'>>=
@