17

これは php や他の言語で実行できることは知っていますが、knitr を使用して次のことが達成できるかどうか疑問に思っていました。

2 つの見出し 1 セクションを持つ Rmarkdown (.rmd) ドキュメントがあるとします。

# This is the first heading for the first document
Lorem ipsum dolor sit amet

# This is the second heading for the first document
plot(object)
  1. 質問 1: 別の .rmd ドキュメントを開く場合、このドキュメントを解析したときに、最初のドキュメントのコンテンツ全体だけでなく、そのコンテンツも表示するようにリンクを作成するにはどうすればよいですか。例えば:

    # This is the first heading for the second document
    Lorem ipsum dolor sit amet
    
    [command goes here to insert the first document]
    

    結果は次のようになります。

    # This is the first heading for the second document
    Lorem ipsum dolor sit amet
    
    # This is the first heading for the first document
    Lorem ipsum dolor sit amet
    
    # This is the second heading for the first document
    [plot shows up here]
    
  2. 質問 2: Knitr を使用すると、ドキュメント 1 の選択した部分のみを選択してドキュメント 2 に挿入できますか? たとえば、見出し 1 とその下のコンテンツのみ、または見出し 2 とそのプロットのみ

4

1 に答える 1

26
  1. それがチャンクオプションchildの目的です。たとえば、second.Rmdでは、次のことができます

    ```{r child='first.Rmd'}
    ```
    
  2. これは少しトリッキーですが、knit_child()手動で呼び出すことができます。

    ```{r echo=FALSE, results='asis'}
    # knit the first three lines of first.Rmd
    cat(knit_child(text = readLines('first.Rmd')[1:3]), sep = '\n')
    ```
    
于 2013-07-11T23:55:25.133 に答える