12

I am creating an Rmarkdown document.

My code chunk checks for the number of columns/rows in the dataset and saves the information in a variable.

{r, echo=FALSE, warning=FALSE}
df_dimenzions <- dim(demo)

I want to use the data/information stored in the variable in the rmarkdown text.

For example... outside of the code chunk, to write plain text such as:
The number of columns is {{df_dimensions[1]}} and the number of rows
is {{df_dimension[2]}}

Is something like this possible in rmarkdown? Again, I'm asking for data that is processed within the rmarkdown, not stored outside of the document?

Also, I am aware that I can paste a concatinated string with the code-chunk. That is not what I am trying to achieve.

Jérôme Teisseire
  • 1,518
  • 1
  • 16
  • 26
Prometheus
  • 1,977
  • 3
  • 30
  • 57
  • Related/possible dup: https://stackoverflow.com/questions/10902504/r-markdown-accessing-variable-from-code-chunk-variable-scope ; https://stackoverflow.com/questions/10629416/is-there-an-r-markdown-equivalent-to-sexpr-in-sweave – pogibas Oct 19 '18 at 19:37

1 Answers1

18

Use `r df_dimensions[1]` in the main text.

Bing
  • 1,083
  • 1
  • 10
  • 20
  • can a variable be printed on top of a document i.e. before it is created later in the document ? – ok1more Nov 30 '21 at 21:14