Programmatically insert text, headers and lists with R markdown

后端 未结 4 2164
时光说笑
时光说笑 2020-12-05 07:23

When using R markdown if one wants to add text using code there are some simple ways to do it.

This is also true for tables, using the kable command is

4条回答
  •  盖世英雄少女心
    2020-12-05 08:08

    You need to construct your wanted markdown in R and use that together with the argument results = 'asis' in your chunk options. Hence, something like the following will do what you want:

    ```{r, results='asis'}
    headers <- list("We","are","your","friends")
    for (i in headers){
      cat("#", i, "\n")
    }
    ```
    

    The for-loop here will create the output

    # We 
    # are 
    # your 
    # friends 
    

    which is used directly as input in the .md document.

提交回复
热议问题