【问题标题】:R markdown: force a character string into more than 1 linesR markdown:强制一个字符串超过 1 行
【发布时间】:2021-12-31 20:33:29
【问题描述】:

我有

---
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 似乎没有做这项工作。

【问题讨论】:

    标签: r string pdf r-markdown


    【解决方案1】:

    你需要逃避杂技,使用\\\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`
    

    【讨论】:

      猜你喜欢
      • 2020-09-08
      • 2011-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-17
      • 1970-01-01
      相关资源
      最近更新 更多