R markdown:强制一个字符串超过 1 行

R markdown: force a character string into more than 1 lines

我有

---
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`

在 PDF 中 test 显示在 1 行中。是否可以在 Rmarkdown 中将 test 字符串编织成 4 行,或者我是否必须在 R 中对其进行预处理? \n 似乎没有完成任务。

你需要转义技巧,使用\\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`