you will need bookdown since rmarkdown doesn't support cross references out of the box.
---
title: '186960'
author: "ChloeCao"
date: "2024-05-20"
output:
bookdown::word_document2
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Code containing condition
Some text ...
```{r condition}
temp <- TRUE
```
## Including Plots
You can also embed plots `r ifelse(temp, "for example \\@ref(fig:pressure) shown below.", "but you said temp is false so i will not produce anything.")`
```{r pressure, eval=temp, echo=temp, fig.cap="Pressure"}
plot(pressure)
```