R markdown:asis 块内的内联代码?

问题描述 投票:0回答:1

我可能对 Markdown 功能越来越贪婪,但是:有没有办法将内联代码添加到 asis 块中?

```{r}
x <- 5
```

```{asis}
The square is `r x^2` # should show up as 'The square is 25'
```
r r-markdown
1个回答
0
投票

这是一个可能的解决方案:

---
title: "Inline code inside asis"
date: "`r Sys.Date()`"
output: html_document
---

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

```{r}
x <- 5
```

```{r, results='asis', echo=FALSE}
cat(paste0("The square is ", x^2, ".")) # should show up as 'The square is 25'
```

这解决了您的问题吗?

中提琴

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.