I have a code chunk "data_prep" which is included at the end of my Rmd file, but I'd like to show its result right at the beginning (after headline 1). The problem is that code chunk "data_prep" needs to run before the chunk named "data_summary" (data_summary depends on data_prep).
How can i change the order in which the code chunks are being evaluated?
---
title: "Untitled"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, warning = FALSE, message = FALSE)
```
```{r}
library(dplyr)
```
# 1
```{r data_summary, ref.label='data_prep'}
```
# 2
```{r}
df_1 <- mtcars %>% sample_n(10)
```
# 3
```{r data_prep, results='hide'}
mtcars_summary <- df_1 %>%
group_by(cyl) %>%
summarise(hp_avg = mean(hp))
mtcars_summary
```
I have also tried the following two variants:
```{r data_prep, echo = TRUE}
```
and
```{r data_summary, dependson='data_prep'}
```