简体   繁体   中英

RMarkdown - second inline code shows code block instead of value

I am trying to show just a couple of variable values, using inline code in RMarkdown. The first inline code shows the value correctly (the number 3), but the second shows the code block instead of the expected value (datos[2] instead of the number 9). Both use the same sintaxis. The wrong output occurs when output is to HTML. Outputing to Word works ok. Any idea why does this behavior occur and how can I fix it? I am using R 3.3.3, RStudio 1.1.419, MacOS X Yosemite. The code is as follows:

---
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]`.

The output is:

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

Thank you very much for your help

Add a r letter in second block.

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

r here works as a statement to tell R to run this code,

datos[2]

and return the number here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM