RMarkdown - second inline code shows code block instead of value

576 views Asked by At

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

1

There are 1 answers

3
Jiaxiang On

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.