Home > Enterprise >  Rmarkdown read_chunk and cross reference
Rmarkdown read_chunk and cross reference

Time:02-02

I have a plots.R file which has following format

## ---- t1-1 ------
plot(pressure)

## --- t2-1 ---
summary(pressure)

I am reading this file via knitr::read_chunk in another Rmarkdown file named force.Rmd. Problem is I want to cross reference it? How can I do that when the chunk label is same as in plots.R

format of force.Rmd file is


`{r}
knitr::read_chunk(plots.R
`

`{r t1-1,echo=F}
`

I want to cross reference this chunk as /@ref(fig:t1-1) but this is not working since the chunk label is the same in plots.R. I am using bookdown package in force.Rmd file in YAML header with fig_caption: yes.

CodePudding user response:

In order to cross-reference figures in bookdown, the figure has to be put in a figure environment to generate the figure number. I believe this requires the figure to have a caption, which is generated with the fig.cap='string' option for that code chunk.

  • Related