
\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}
Pregunta:
¿Cómo manejo una situación en la que "xyplotFacSpecTotVarTest.pdf" no existe? Archivo generado a partir del contenido de una tabla, que a su vez puede tener datos o no. Errores finales en el proceso de generación de PDF si falta "xyplotFacSpecTotVarTest.pdf" ¿Cómo puedo manejar este escenario? Probé /IfFileExist pero no parece funcionar. Consulte la siguiente implementación.
\IfFileExists{{image_dir}{xyplotFacSpecTotVarTest.pdf}} {
\clearpage
\begin{figure}[!h]
\centering
\includegraphics{\Sexpr{image_dir}{xyplotFacSpecTotVarTest.pdf}}
\typeout{File Exist: xyplotFacSpecTotVarTest.pdf}
\caption{Total Variance vs. Sum of Factor and Specific Variance, All Instruments Passing Exposure Model.}
\end{figure} }
{\typeout{File DOESNT Exist: xyplotFacSpecTotVarTest.pdf}}
Respuesta1
Mirando las etiquetas, supongo que usas knitr
. ¿Por qué no dejar que R determine (silenciosamente) si el archivo existe?
<<chunkname,results='asis',echo=FALSE>>=
if (file.exists(file.path(image_dir, "xyplotFacSpecTotVarTest.pdf"))) {
cat("\\clearpage\n")
cat("\\begin{figure}[!h]\n")
# and so on
}
else {
cat("\\textbf{File does not exist.}\n\n")
}
@
Tenga en cuenta la results='asis'
opción de fragmento. Cada cat
cadena 'd se enviará al .tex
archivo tal como está (de ahí el nombre de la opción). En otras palabras, cada cat
cadena 'd será un comando LaTeX que se compilará.
Incluso puedes generalizar el código anterior creando una función R elegante, por ejemplo include_if_exists(filename)
, y reutilizarla en muchos fragmentos.