2013-05-08 61 views
4

我正在使用knitr將R代碼嵌入到markdown(.Rmd)文件中。我使用Pandoc將文件轉換爲PDF文件。我.Rmd文件的內容是這樣的:參考R標記中的knitr塊

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

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


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

summary(cars) 

``` 

在那裏說LINK文本塊NAMED MY.ANALYSIS在這裏,我能夠提供的輸出PDF鏈接到一個名爲my.analysis代碼塊?

相信OP問過類似的,但略有不同的問題在這裏:figure captions, references using knitr and markdown to html

回答

1

這樣做:

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) 

``` 

然後變相降價文件(不RMD)的PDF。

這也適用使用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) 

``` 

然後,您可以將HTML文件轉換爲PDF格式。

+0

我現在意識到問題是要獲得內部鏈接。這個答案沒有解決這個問題。 – 2013-05-08 17:52:45

+1

我想也許使用'\ ref {sec}'和'label {sec}'並將md轉換爲pdf將會起作用,但它不會。 – 2013-05-08 22:41:32