RMarkdown - изменить цвет встроенного кода - PullRequest
0 голосов
/ 06 июня 2018

Я использую встроенный код в RMarkdown , и я хотел бы, чтобы весь текст, являющийся результатом встроенного кода, был другого цвета в документе.В этом примере я бы хотел, чтобы heat.colors был красным по всему документу.Есть ли способ сделать это?

Ответы [ 2 ]

0 голосов
/ 08 июня 2018

Или вы можете использовать text_spec в kableExtra.Он буквально делает то же самое, но чуть более буквально.Подробнее здесь

---
title: ''
output: html_document
---

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

## R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

This is inline code: `r text_spec(colnames(mtcars)[1], color = "red")`.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

```{r cars}
summary(cars)
```

## Including Plots

You can also embed plots, for example:

### This is more inline code `r text_spec(colnames(mtcars)[2], color = "red")`.

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
0 голосов
/ 06 июня 2018

Вы можете сделать что-то вроде:

---
title: ''
output: html_document
---

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

```{css echo=FALSE}
.custom-inline {
  color: red;
  font-weight: 700
}
```
## R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

This is inline code: `r sprintf("<span class='custom-inline'>%s</span>", colnames(mtcars)[1])`.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

```{r cars}
summary(cars)
```

## Including Plots

You can also embed plots, for example:

### This is more inline code `r sprintf("<span class='custom-inline'>%s</span>", colnames(mtcars)[2])`.

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.

, чтобы получить:

enter image description here

Шаблоны по умолчанию не переносят встроенные чанкив классифицированном теге <span>, поэтому вы должны сделать это вручную.Вы также можете создать функцию для этого.

...