Julien Colomb
Julien Colomb

Reputation: 563

knitr: print text but get rid of verbatim in the tex file

I am using knitr to produce automatic reports of my studies. I want to print or not print some text depending on different variables in the final document. I got rid of the "##" using comment=NA, but knitr put everyting between a verbatim class in the tex file.

I am calling knitr via a R script:

INITIATION = T
rmarkdown::render("main.Rmd")

in main.rdm, I have:

```{r, results:asis, comment=NA,echo=FALSE}
if (INITIATION){
  #print (as.character(Initiation_form$Commentspre))
  print ("testing that")
}

```

`r Initiation_form$Commentspre`

which gives me in the tex file:

\begin{verbatim}
[1] "testing that"
\end{verbatim}
testing that

the inline text works, but I cannot put it inside a loop or a if argument... as a bonus, how can I get rid of the [1]

Upvotes: 1

Views: 353

Answers (1)

Thierry
Thierry

Reputation: 18487

Use cat() instead of print() to remove the [1].

Use results = 'asis' instead of results:asis

Upvotes: 4

Related Questions