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

feat: add render_reports function

parent 0f2447b5
No related branches found
No related tags found
No related merge requests found
......@@ -8,3 +8,8 @@ License: AGPL (>= 3)
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
Imports:
bookdown,
yaml
Suggests:
tinytex
......@@ -5,4 +5,6 @@ export(add_gitignore)
export(getDataPath)
export(iconv_filename)
export(loadConfig)
export(render_report)
export(render_reports)
importFrom(magrittr,"%>%")
#' @rdname render_reports
#' @export
render_report <- function(path_report,
path_publish,
output_format = Sys.getenv("BOOKDOWN_FORMAT", "bookdown::gitbook"),
clean_cache = FALSE,
...) {
stopifnot(output_format %in% c("bookdown::gitbook", "bookdown::pdf_book"))
if (output_format == "bookdown::pdf_book") {
if (!require("tinytex")) install.packages("tinytex")
}
if (clean_cache) {
cache_dir <- list.files(path = path,
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)
dir.create(output_dir,
recursive = TRUE,
showWarnings = FALSE)
attached_packages <- (.packages())
bookdown::render_book(path,
output_format = output_format,
output_dir = output_dir,
envir = new.env(),
...)
# detach all packages used in the knit
sapply(
setdiff((.packages()), attached_packages),
function(x) detach(paste0("package:", x),
unload = TRUE,
character.only = TRUE))
NULL
}
#' Render reports
#'
#' @param path_reports [character] path for the reports
#' @param path_report [character] report path
#' @param reports [character] subfolders containing each report
#' @param path_publish [character] rendering output path
#' @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
#' @param ... Parameters passed to [render_report] and [bookdown::render_book]
#'
#' @return `NULL`, this function is used for side effect.
#' @export
#' @rdname render_reports
#'
#' @examples
render_reports <- function(path_reports = "./reports",
reports = list.files(path_reports, pattern = "^[0-9]{2}-.*$"),
path_publish = "./public/reports",
...) {
options(knitr.duplicate.label = 'allow')
message("output_format=", output_format)
message("folder list:")
invisible(sapply(files, message))
for(file in files){
message("*******************************************************************")
message("** RENDER ", file)
message("*******************************************************************")
path <- file.path(path_reports, file)
render_report()
}
NULL
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/render_report.R, R/render_reports.R
\name{render_report}
\alias{render_report}
\alias{render_reports}
\title{Render reports}
\usage{
render_report(
path_report,
path_publish,
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",
...
)
}
\arguments{
\item{path_report}{\link{character} report path}
\item{path_publish}{\link{character} rendering output path}
\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}
\item{clean_cache}{\link{logical} clean Rmarkdown cache files}
\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}{\link{character} subfolders containing each report}
}
\value{
\code{NULL}, this function is used for side effect.
}
\description{
Render reports
}
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