Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Rmarkdown read_chunk and cross reference

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel


`{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.

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading