1

Is it possible to interpolate R code or variable values in R markdown documents? I mean something like:

---
title: "Behavioural report"
author: "My name"
date: "Some date here"
output: pdf_document
---

```{r echo=FALSE}
X = 1.28473
```

Suppose that this is my R markdown document and I want to say that the value
of the variable X = {Here I want the value of X to appear}. And then blah...

So I want the value 1.28473 to appear just after the text 'X ='.

Thanks in advance!

1 Answer 1

2

Try using the following in place of your {}

`r X`

You can also do inline computations:

`r mean(rnorm(50))`
3
  • Great!! Thanks a lot!! Apr 14, 2016 at 19:32
  • I'm doing that and getting some weird scientific notation or something. My markdown says m = `r m`, (m == 33634), and it renders as m = 3.363410^{4}
    – Sigfried
    Sep 5, 2019 at 18:28
  • Here's the answer to my problem: stackoverflow.com/questions/25946047/…
    – Sigfried
    Sep 5, 2019 at 18:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.