2014-05-02 43 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'>>= 
@