Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reference knitr chunk in R markdown

I'm using knitr to embed R code within a markdown (.Rmd) file. I'm converting the file to a PDF file with Pandoc. The contents of my .Rmd file looks like this:

Report
========================================================

This is my report. Some analysis is included in LINK TO CHUNK NAMED MY.ANALYSIS HERE


```{r my.analysis, echo=FALSE}

summary(cars)

```

Where it says LINK TO CHUNK NAMED MY.ANALYSIS HERE, am I able provide a link to the code chunk named my.analysis in the outputted PDF?

I believe the OP asked a similar, but slightly different question here: figure captions, references using knitr and markdown to html

like image 641
luciano Avatar asked Nov 03 '22 22:11

luciano


1 Answers

Do this:

Report
========================================================

This is my report. Some analysis is included in \href{http://stackoverflow.com/q/16445247/1000343}{LINK TO CHUNK NAMED MY.ANALYSIS HERE}


```{r my.analysis, echo=FALSE}

summary(cars)

```

And then covert the markdown file (not Rmd) to the PDF.

This also works using the devel version of reports:

```{r setup, include=FALSE}
# set global chunk options
opts_chunk$set(cache=TRUE)
library(reports); library(knitr); 
```
Report
========================================================

This is my report. Some analysis is included in `r HR("http://stackoverflow.com/q/16445247/1000343", "LINK TO CHUNK NAMED MY.ANALYSIS HERE")`


```{r my.analysis, echo=FALSE}

summary(cars)

```

You then convert the html file to pdf.

like image 57
Tyler Rinker Avatar answered Nov 09 '22 15:11

Tyler Rinker