knit one rmarkdown file from another rmarkdown file and render output

Hello

I am "calling" one rmd file from another, because I am collecting the same type of data from different locations. So I have created a 'generic' rmd html output file and am trying to use it in a separate rmd file I am creating for each location. So as follows:

---
title: "location1"
weight: 50
output:
  blogdown::html_page:
    toc: true
    toc_depth: 1
    number_sections: true
---
 
```{r include=FALSE}
#knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE)
library(here)
# load site data
load(here("saved_data/rdata_woburn_sitedata.RData"))

# copy it to the generic rdata name for the generic rmd file
file.copy(from = (here("saved_data/rdata_woburn_sitedata.RData")), to = file.path(here("saved_data/rdata_get_sitedata.RData")))

# fetch the generic rmd file
knit(here("rmd_template_two_channel.Rmd"))

However, this creates an md file named "rmd_template_two_channel.md", snippet below:.


# Woburn Hill 
Click on marker for site details.    

```{=html}
<div id="htmlwidget-fbf7a7d74ceb77dbca83" style="width:100%;height:480px;" class="widgetframe html-widget"></div>
<script type="application/json" data-for="htmlwidget-fbf7a7d74ceb77dbca83">{"x":{"url":"fgfgk_files/figure-html//widgets/widget_unnamed-chunk-4.html","options":{"xdomain":"*","allowfullscreen":false,"lazyload":false}},"evals":[],"jsHooks":[]}</script>

Is there a way I can 'call' the generic rmd file to create html output for each location rmd file?

Thanks

See this S/O post.

I would approach it differently, by creating a function, f, that renders a location dataset, x, into an object,y that can be rendered with

```{=html}
f(location)

Thanks - the link from S/O worked and the link from S/O to https://yihui.org/knitr/demo/child/ was also informative.

So I ended up instead with

```{r include= FALSE}
# load site data
load(here("saved_data/rdata_woburn_sitedata.RData"))

# copy it to the generic rdata name in the child rmd
file.copy(from = (here("saved_data/rdata_woburn_sitedata.RData")), to = file.path(here("saved_data/rdata_get_sitedata.RData")), overwrite = TRUE)
---```

  ```{r child=(here("content/docs/_rmd_child_all_channel.Rmd")), eval=TRUE}
---  ```
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.