First solution : ref.label
You can use ref.label chunk option to reference another chunk and get the code.
In your case it works
---
title: "R Notebook"
output: html_document
---
```{r, ref.label="mean-speed", echo = FALSE}
```
I can get the value of `mean_speed` even if it is define in a chunk after. Mean speed = `r mean_speed`.
```{r cars-plot, fig.cap = "plot of cars"}
plot(cars)
```
```{r mean-speed}
mean_speed <- mean(cars$speed)
```
This trick will place the last chunk at the beginning of the document. It won't work in all case but in yours it could be ok.
You can reference several chunks in one if required
```{r exec-summary, echo = FALSE, ref.label = c("model", "table")}
```
Another solution: caching mechanism.
There is a fonction knitr::load_cache() that allows to load all objects or specific one. You can activate the cache with cache = 'TRUE' and you'll need to pass on the document to make it work.
See the knitr example 114 in knitr example repo:
Also, as you are \@ref(fig:cars-plot), are you using a bookdown format ? not classic html_document I think.
Hope you'll make it work ! 