Is it possible to use R code, with knitr, for control flow in document generation? For instance, could I write a conditional block in R that output one conclusion under one condition, or another conclusion otherwise; or perhaps use R loops to generate documentation for different input conditions; etc.?
This doesn't work, but to give you an idea of what I'm looking for:
\section{Conclusion}
%% begin.rcode
% if (condition) {
Everything is awesome!
% } else {
All is lost!
% }
% for (x in c(1:3)) {
foo \rinline(x)
% }
%% end.rcode
I would want this to render to (assuming condition
is true):
\section{Conclusion}
Everything is awesome!
foo 1
foo 2
foo 3