2

Is it possible to perform simple calculations in text with RMarkdown? For example when typing:

...compound A (50 mg, ?0.05/2? mmol) was added...

where ? is some syntax to let RMarkdown know that it needs to calculate what is in between rather than just exporting it as text, to get in the word output file:

...compound A (50 mg, 0.025 mmol) was added...

I found this relevant question about LaTeX: Is there a calculator with LaTeX-syntax? but dont know if it is possible in RMarkdown. It seems like an obvious feature to have.

Outlander
  • 533
  • 7
  • 12

1 Answers1

5

You can include R code inline by enclosing your expression with `r `. That is, if you put the following in your RMarkdown (.Rmd):

...compound A (50 mg, `r 0.05/2` mmol) was added...

It will render as:

...compound A (50 mg, 0.025 mmol) was added...

For more detail see

https://rmarkdown.rstudio.com/lesson-4.html and

https://bookdown.org/yihui/rmarkdown/r-code.html

markdly
  • 4,394
  • 2
  • 19
  • 27