I have
---
title: "test"
output: pdf_document
---
Below should be in four lines
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
test<-c("This should be in the first line \n This in the second line \n This in the third line \n This in the fourth line")
```
`r test`
in the PDF test
is displayed in 1 line. Is it possible to knit the test
string into 4 lines within Rmarkdown or do I have to preprocess it in R? \n
does not seem to do the job.
CodePudding user response:
You need escaping acrobatics, use \\\n
.
---
title: "test"
output: pdf_document
---
Below should be in four lines
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
test<-c("This should be in the first line \\\n This in the second line \\\n This in the third line \\\n This in the fourth line")
```
`r test`