Given the following R knitr document:
\documentclass{article}
\begin{document}
<<data>>=
opts_chunk$set(comment = NA) # omits "##" at beginning of error message
x <- data.frame(x1 = 1:10)
y <- data.frame()
@
<<output_x>>=
if (nrow(x) == 0) stop("x is an empty data frame.") else summary(x)
@
<<output_y>>=
if (nrow(y) == 0) stop("y is an empty data frame.") else summary(y)
@
\end{document}
As expected, the last chunk returns an error with the custom message. The compiled PDF looks a little different:
Error: y is an empty data frame.
I want this text to just be
y is an empty data frame.
Without the Error:
part or the red color. Can I achieve this? How?
Edit: I was able to make it in the mock data through the following workaround:
<<output_y>>=
if (nrow(y) == 0) cat("y is an empty data frame.") else summary(y)
@
However, that doesn't work with my real data, because I need the function to be stopped at that point.
break
statement to stop the function? – Rich Scrivenbreak
at the end of theif
statement just gives me another error:no loop for break/next, jumping to top level
. The function is not inside of a loop, it's a simple function to create some subsets and make some calculations to create a latex table. – Waldir Leoncio