首页 > 解决方案 > RMarkdown - 第二个内联代码显示代码块而不是值

问题描述

我正在尝试使用 RMarkdown 中的内联代码仅显示几个变量值。第一个内联代码正确显示值(数字 3),但第二个显示代码块而不是预期值(datos[2] 而不是数字 9)。两者都使用相同的sintaxis。输出到 HTML 时会出现错误输出。输出到 Word 工作正常。知道为什么会发生这种行为,我该如何解决?我正在使用 R 3.3.3、RStudio 1.1.419、MacOS X Yosemite。代码如下:

---
title: "Untitled"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
datos <- c(3,9,4,7)
```
The first value in datos is `r datos[1]` and the second is `r datos[2]`.

输出是:

Untitled
The first value in datos is 3 and the second is datos[2].

非常感谢您的帮助

标签: rr-markdowninline-code

解决方案


在第二个块中添加一个r字母。

The first value in datos is `r datos[1]` and the second is `r datos[2]`.

r这里用作告诉 R 运行此代码的语句,

datos[2]

并在此处返回号码。


推荐阅读