Search code examples
rr-markdownknitrinlinehtmltools

Including external markdown file covering inline code through includeMarkdown


I would like to include external markdown file covering inline code as well. Once I hit the Knit on RStudio, it does show only code text rather than the actual value of sys.time. If I place the content of about.md into the main.Rmd, there is no issue. The point should be related with includeMarkdown but it does not take any parameter except than path. Any suggestions ? Thanks in advance

main.Rmd

---
title: "test"
author: "test"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    social: menu
    vertical_layout: fill
---
```{r}
  htmltools::includeMarkdown('about.md')
```

about.md

Today is `r format(Sys.time(), "%d %B %A %Y")`

Current Output

Today is r format(Sys.time(), "%d %B %A %Y")

Solution

  • htmltools::includeMarkdown() only includes plain Markdown, not R Markdown. Your about.md is actually R Markdown---it contains R code to be evaluated.

    To include an R Markdown document in another one, you can use the chunk option child:

    ```{r, child='about.Rmd'}
    ```
    

    I suggest you rename about.md to about.Rmd.