0

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?

1

Do the following:

\documentclass[10pt,letterpaper]{article}

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

\Sexpr{data}
\end{document}
2
  • 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? – tallharish Aug 16 '15 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 – R. Schumacher Aug 17 '15 at 0:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.