I'm writing a script that creates custom pdf-reports for a few hundred teams. Based on the data per team the code chooses what advice and how many pieces of advice to print in the PDF-file for this specific team. I'm able to print different advice per team, or print no advice if there is none, but I fail to prevent him printing the line-end.
The code below will only print the header and advice when it is relevant, but it will always print a empty lines.
When 6 is not relevant this line should be directly followed by the fourth line of this example
### `r if(params$df$relevant[6]){params$df$Heading[6]}`
`r if(params$df$relevant[6]){params$df$Advice[6]}`
When 6 is not relevant this line should directly below the first line of this example, without white lines in between
In my workflow I start in R which imports and analyses data for all teams. Per team it calls rmarkdown::render()
to open a template .RMD/RMarkdown file, sending the advice text in a df via the parameters from the R-script to the template.
A brief description of other strategies I tried and failed with (and which would warrant a new question if the current one is a dead end?):
ifelse()
function instead. That doesn't seem to create a Header if you type ###
in front of the rowI'm new to this forum. Please let me know if I can phrase the question more clearly without giving irrelevant info.
Welcome to SO!
Not sure if there's a simpler approach but in similar situations I like to avoid markdown and inline R code and instead wrap it up in a code chunk (which also makes control flow easier):
```{r, results='asis', echo=F}
a <- "When 6 is not relevant this line should be directly followed
by the fourth line of this example"
b <- "When 6 is not relevant this line should directly below the
first line of this example, without white lines in between"
if(params$params$df$relevant[6]) {
cat(a, paste0('\\subsubsection{', params$df$Heading[6], '}'), b)
} else {
cat(a, "\\newline", b)
}
```
(\subsubsection
and \newline
are LaTeX commands for level-three heading and linebreak, respectively.)