Extract only text from Rmd documents

后端 未结 1 1487
感情败类
感情败类 2021-01-19 03:53

Not even sure if this is possible, but is there a way to extract only the raw text portion of the .Rmd file and discard any code? Or basically converting an .Rmd file into

1条回答
  •  无人及你
    2021-01-19 04:23

    You can knit document without evaluating and including code.

    Here's an example of dummy document foo.Rmd:

    # Header 1

    foo

    ## Header 2

    bar

    ## Header 22

    foobar

    ```{r}
    1
    ```

    text text text

    ```{r}
    print(2)
    ```

    We can knit this document using knitr::knit("foo.Rmd"), but in this case code chunks will be included in text. To deal with this we need to set knitr options:

    library(knitr)
    opts_chunk$set(list(echo = FALSE, eval = FALSE))
    knit("foo.Rmd")
    

    This command will create output document foo.md only with text.

    0 讨论(0)
提交回复
热议问题