Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse text as-is in knitr for rmarkdown to docx?

Is there a way to parse text as is in rmarkdown, like the <pre> tag for HTML but for docx (Microsoft Word) export with knitr? When I use the tag <pre> it hides it in words... I could use a R code chunk and commenting it out but maybe there is a better way...

I would like to copy the output from R and paste it in my text markdown so it is always there...

For example

[1] “Results”  
1   2   3   4   5   6   7

gives the following in Word after knitr export:

[1] “Noeuds” 2 3 4 5 6 7

I would like to keep the same formatting as the example..

This is what I use at the moment with an R code chunk:

```{r}
#[1] “Results”  
#    1   2   3   4   5   6   7
```
like image 653
R. Prost Avatar asked Sep 11 '25 13:09

R. Prost


1 Answers

Either indent the text block by four spaces, or put it in a fenced code block, e.g.,

```
[1] “Results”  
1   2   3   4   5   6   7
```

See Pandoc's documentation on verbatim (code) blocks.

like image 121
Yihui Xie Avatar answered Sep 13 '25 02:09

Yihui Xie