# Print binary output in knitr

Just showing an example to represent my seemingly simple problem.

i generate a variable with random TRUE/FALSE.

<<>>=
data <- sample(c(TRUE, FALSE), size = 1, replace = TRUE)
@


Somewhere in the TeX (knitr), i need to print whether its TRUE or FALSE.

\Sexpr{!is.na(data)}


but my text output is blank. I am not sure whats the problem?

Do the following:

\documentclass[10pt,letterpaper]{article}

\begin{document}
<<>>=
data <- sample(c(TRUE, FALSE), size = 1, replace = TRUE)
@

\Sexpr{data}
\end{document}

• Thanks R. Schumacher. This works. Now how about for variables with NA? Can I display Exists / NA if the variable has a value other than NA, or print NA? Aug 16, 2015 at 16:56
• I suspect that this can be done, but because of the specific issues in dealing with NA in R this question will get a better answer on stackoverflow.com/questions/tagged/r Aug 17, 2015 at 0:03