Skip to content
Snippets Groups Projects
Commit af863009 authored by David Dorchies's avatar David Dorchies
Browse files

fix: bugs in render_reports

parent 0f80ad90
No related branches found
No related tags found
No related merge requests found
#' @rdname render_reports
#' @inheritParams bookdown::render_book
#' @export
render_report <- function(path_report,
path_publish,
render_report <- function(input,
output_dir,
output_format = Sys.getenv("BOOKDOWN_FORMAT", "bookdown::gitbook"),
clean_cache = FALSE,
...) {
......@@ -11,23 +12,23 @@ render_report <- function(path_report,
if (output_format == "bookdown::pdf_book") {
if (!require("tinytex")) install.packages("tinytex")
}
message("output_format=", output_format)
if (clean_cache) {
cache_dir <- list.files(path = path,
cache_dir <- list.files(path = input,
pattern = "_cache$",
include.dirs = TRUE,
full.names = TRUE)
unlink(cache_dir, recursive = TRUE)
}
cfg_bookdown <-
yaml::read_yaml(file.path(path, "_bookdown.yml"))
unlink(file.path(path, paste0(cfg_bookdown$book_filename, ".*")))
output_dir <- file.path(path_publish, file)
yaml::read_yaml(file.path(input, "_bookdown.yml"))
unlink(file.path(input, paste0(cfg_bookdown$book_filename, ".*")))
dir.create(output_dir,
recursive = TRUE,
showWarnings = FALSE)
attached_packages <- (.packages())
bookdown::render_book(path,
bookdown::render_book(input,
output_format = output_format,
output_dir = output_dir,
envir = new.env(),
......
#' Render reports
#'
#' @param path_reports [character] path for the reports
#' @param path_report [character] report path
#' @param reports_dir [character] path for the reports
#' @param reports [character] subfolders containing each report
#' @param path_publish [character] rendering output path
#' @param publish_dir [character] rendering output path relatively to the report
#' folder which is in format `"./reports/my_report"`
#' @param output_format output format, see [bookdown::render_book]. Only
#' `"bookdown::gitbook"` and `"bookdown::pdf_book"` are currently handled
#' @param clean_cache [logical] clean Rmarkdown cache files
......@@ -14,26 +14,24 @@
#' @rdname render_reports
#'
#' @examples
render_reports <- function(path_reports = "./reports",
reports = list.files(path_reports, pattern = "^[0-9]{2}-.*$"),
path_publish = "./public/reports",
render_reports <- function(reports_dir = "./reports",
reports = list.dirs(reports_dir),
publish_dir = "../../public/reports",
...) {
options(knitr.duplicate.label = 'allow')
message("output_format=", output_format)
message("folder list:")
invisible(sapply(files, message))
invisible(sapply(reports, message))
for(file in files){
for(report in reports){
message("*******************************************************************")
message("** RENDER ", file)
message("** RENDER ", report)
message("*******************************************************************")
path <- file.path(path_reports, file)
render_report()
path <-
render_report(input = file.path(reports_dir, report),
output_dir = file.path(publish_dir, report),
...)
}
NULL
}
......@@ -6,24 +6,31 @@
\title{Render reports}
\usage{
render_report(
path_report,
path_publish,
input,
output_dir,
output_format = Sys.getenv("BOOKDOWN_FORMAT", "bookdown::gitbook"),
clean_cache = FALSE,
...
)
render_reports(
path_reports = "./reports",
reports = list.files(path_reports, pattern = "^[0-9]{2}-.*$"),
path_publish = "./public/reports",
reports_dir = "./reports",
reports = list.files(reports_dir, pattern = "^[0-9]{2}-.*$"),
publish_dir = "./public/reports",
...
)
}
\arguments{
\item{path_report}{\link{character} report path}
\item{input}{A directory, an input filename or multiple filenames. For a
directory, \file{index.Rmd} will be used if it exists in this (book)
project directory. For filenames, if \code{preview = TRUE}, only files
specified in this argument are rendered, otherwise all R Markdown files
specified by the book are rendered.}
\item{path_publish}{\link{character} rendering output path}
\item{output_dir}{The output directory. If \code{NULL}, a field named
\code{output_dir} in the configuration file \file{_bookdown.yml} will be
used (possibly not specified, either, in which case a directory name
\file{_book} will be used).}
\item{output_format}{output format, see \link[bookdown:render_book]{bookdown::render_book}. Only
\code{"bookdown::gitbook"} and \code{"bookdown::pdf_book"} are currently handled}
......@@ -32,9 +39,11 @@ render_reports(
\item{...}{Parameters passed to \link{render_report} and \link[bookdown:render_book]{bookdown::render_book}}
\item{path_reports}{\link{character} path for the reports}
\item{reports_dir}{\link{character} path for the reports}
\item{reports}{\link{character} subfolders containing each report}
\item{publish_dir}{\link{character} rendering output path}
}
\value{
\code{NULL}, this function is used for side effect.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment