R/include.R

Defines functions rmd_child process_links

Documented in rmd_child

#' Helper functions to include a (R)markdown documents in another
#' Rmarkdown document
#'
#' @details
#' `rmd_child()` helps include an Rmarkdown document as a child. You can use
#' it likes this:
#' ````
#' ```{r child = rmd2rd::rmd_child("another.Rmd)}
#' ```
#' ````
#'
#' @param path Path to the (R)md file.
#' @return The path of the transformed Rmd child document.
#'
#' @export

rmd_child <- function(path) {
  stopifnot(is_string(path), file.exists(path))
  path
}

process_links <- function(path) {
  tmp <- tempfile(fileext = ".Rmd")
  lines <- readLines(path)
  txt <- paste(lines, collapse = "\n")
  esc <- add_linkrefs_to_md(txt)
  lines2 <- strsplit(esc, "\n", fixed = TRUE)[[1]]
  writeLines(lines2, tmp)
  tmp
}
gaborcsardi/rmd2rd documentation built on Nov. 4, 2019, 1:01 p.m.