Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use variable in Rmarkdown text

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.

like image 790
Prometheus Avatar asked Oct 19 '18 19:10

Prometheus


People also ask

How do you use variables in Markdown?

The idea is pretty simple, Markdown has a concept of reference links or reference-style links that allows us to define a value to a reference variable and then refer to that value later in the same document. This is my [random value] located somewhere in my Markdown document.

Can R markdown be interactive?

If you include an interactive element in a static output format, like a PDF, R Markdown will embed a screenshot of the element. Learn more about interactive documents with R Markdown at Interactive Documents.

How do you write text in R markdown?

Rmd file, you may now add text to your document. You may start with the most basic word processing—simply typing your text below the YAML header section. If you want to start a new paragraph, you can simply hit Enter twice on your key- board, and begin writing again.

What is knitr in Rmarkdown?

RMarkdown is an extension to markdown which includes the ability to embed code chunks and several other extensions useful for writing technical reports. The rmarkdown package extends the knitr package to, in one step, allow conversion between an RMarkdown file (.Rmd) into PDF, HTML, word document, amongst others.


1 Answers

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

like image 70
Bing Avatar answered Nov 04 '22 18:11

Bing