【问题标题】:Format Code As a Code Block in R Markdown在 R Markdown 中将代码格式化为代码块
【发布时间】:2017-12-05 22:36:44
【问题描述】:

无论如何,是否可以将代码格式化为许多网站提供的“代码”格式,例如 R Markdown 中的 Stackoverflow。

我希望能够执行以下操作:

采用income ~ education + parental_income 形式的任何模型 ...

我想在最终编织文档时模拟 R markdown 中的灰色文本,以便于阅读。

【问题讨论】:

  • RMarkdown 是 Markdown 的超集(即包括所有 Markdown 功能 + 额外独特的功能),因此在您的文档中使用像 `income ~ education + parental_income` 这样的反引号应该以相同的方式工作。
  • 哇。巨大的,如果是真的。

标签: r


【解决方案1】:

可以使用反引号或缩进 4 个空格来生成 HTML <code> </code> 标记块的等效项。这是说明此行为的 Rmd 文档。

---
title: "Sample Document"
author: "bigNumber"
date: "12/5/2017"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## R Markdown

here is some example code written in R Markdown. If we want to enter a code block we use the backtick, such as `inc ~ ed + occ`. 

If we want a code block with multiple lines, indenting by 4 spaces also works

    # first line of code
    for(i in 1:100) {
       # do something here
    }

More text after the code block ends. 

...和输出。不幸的是,我必须包含一个图像以显示它正确呈现。

【讨论】:

    【解决方案2】:

    ``` If you'd rather not indent your code block by four spaces, you can use triple back-ticks on separate lines. ```

    https://bookdown.org/yihui/rmarkdown/markdown-syntax.html#block-level-elements

    【讨论】:

      【解决方案3】:

      如果你想要一个灰色的字符串作为背景,html 可以工作

      Changing chunk background color in RMarkdown

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-02-26
        • 1970-01-01
        • 1970-01-01
        • 2013-05-20
        • 1970-01-01
        • 2019-04-13
        • 2023-03-16
        • 2012-07-03
        相关资源
        最近更新 更多