Share common chunks in Markdown

I’ve copied codes into parent/child program and located the child as C:/temp/child.Rmd. The statements in parent program

title: "parent"
output: pdf_document

knitr::opts_chunk$set(echo = TRUE)

library(dplyr)
library(ggplot2)
src <- lapply(
  sort(unique(iris$Species)), 
  FUN = function(x) {
    knitr::knit_expand(
      file = here::here("L:/Statunit/Nancy/CAH/pgm/child1.Rmd"), 
      title = x
    )
  }
)

r knitr::knit(text = unlist(src))

The statements in child program

title: "child1"
output: pdf_document

{{title}}

iris %>%
  filter(Species == "{{title}}") %>%
  ggplot() +
  aes(x = Sepal.Length, y = Sepal.Width) +
  geom_point() +
  labs(title = "{{title}}")

After I knit parent program, the error message as below. Why and how to fix it?
Quitting from lines 14-23 (trypc.Rmd)
Error in file(con, "r") : cannot open the connection
Calls: ... one_string -> paste -> read_utf8 -> readLines -> file
Execution halted

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