2014-05-02 16 views
3

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

我该怎么办?

\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} 
+0

如何处理“xyplotFacSpecTotVarTest.pdf”不存在的情况。文件从表格中的内容生成,反过来可能有或没有数据。最终的PDF生成过程错误,如果它缺少“xyplotFacSpecTotVarTest.pdf”我如何处理这种情况? – user2120927

回答

6

把你的小节放在不同的文件中,比如sub.Rnw。然后有条件地将其包含在主文档中,例如

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