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

4

如何根据某些条件打开/关闭特定子部分的显示?例如,仅当 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}

如何处理“xyplotFacSpecTotVarTest.pdf”文件不存在的情况。该文件是由表格中的内容生成的,而该表格可能具有或不具有数据。如果缺少“xyplotFacSpecTotVarTest.pdf”,最终的PDF生成过程将出现错误。我应该如何处理这种情况? - Manish
1个回答

6

将您的子节放在另一个文件中,比如sub.Rnw。然后以条件方式在主文件中包含它,例如:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接