output markdown in r code chunk

后端 未结 1 1762
臣服心动
臣服心动 2021-02-02 01:13

I have a R markdown file that I want to output rmarkdown from the script itself. For example, I would have the following simple code in an Rmd file.

---
title: \         


        
1条回答
  •  走了就别回头了
    2021-02-02 02:10

    Why build the header markup (either in markdown or HTML) manually? Try inline R expressions or some helper functions in pander (to generate markdown programatically):

    ---
    title: "test"
    author: "johndoe"
    date: "September 5, 2015"
    output: html_document
    ---
    
    ```{r setup, include=FALSE}
    knitr::opts_chunk$set(echo = TRUE)
    ```
    
    ## `r 'This is a Heading in Code'`
    
    ```{r title, results='asis'}
    library(pander)
    pandoc.header("This is a Heading in Code", level = 2)
    ```
    
    ```{r cars, results='asis'}
    summary(cars)
    ```
    

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