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

feat: add use_reports for creating reports structure

parent 1a1bdb3b
No related branches found
No related tags found
No related merge requests found
......@@ -5,7 +5,9 @@ export(add_gitignore)
export(getDataPath)
export(iconv_filename)
export(loadConfig)
export(pkg_sys)
export(render_report)
export(render_reports)
export(updateMermaid)
export(use_reports)
importFrom(magrittr,"%>%")
#' Set reports folder structure
#'
#' @param path Destination folder for reports and templates
#' @param overwrite Allow overwriting templates folder
#'
#' @return Use for side effect.
#' @export
#'
#' @examples
use_reports <- function(path = ".", overwrite = FALSE) {
# Copy templates
if (dir.exists(file.path(path, "templates"))) {
if (overwrite) {
warning("Folder ", file.path(path, "templates"), " is overwritten")
} else {
stop("Folder ", file.path(path, "templates"), " already exists")
}
}
file.copy(from = pkg_sys("templates"),
to = path,
recursive = TRUE,
copy.date = TRUE)
# Create reports folder
file.copy(from = pkg_sys("reports"),
to = path,
recursive = TRUE,
copy.date = TRUE)
invisible()
}
#' Wrapper for `system.file` for this package
#'
#' @inherit base::system.file
#'
#' @return
#' @export
#'
#' @examples
#' pkg_sys()
#'
pkg_sys <- function(
...,
package = utils::packageName(),
lib.loc = NULL,
mustWork = FALSE
) {
system.file(
...,
package = package,
lib.loc = lib.loc,
mustWork = mustWork
)
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils.R
\name{pkg_sys}
\alias{pkg_sys}
\title{Wrapper for \code{system.file} for this package}
\usage{
pkg_sys(..., package = utils::packageName(), lib.loc = NULL, mustWork = FALSE)
}
\arguments{
\item{...}{character vectors, specifying subdirectory and file(s)
within some package. The default, none, returns the
root of the package. Wildcards are not supported.}
\item{package}{a character string with the name of a single package.
An error occurs if more than one package name is given.}
\item{lib.loc}{a character vector with path names of \R libraries.
See \sQuote{Details} for the meaning of the default value of \code{NULL}.}
\item{mustWork}{logical. If \code{TRUE}, an error is given if there
are no matching files.}
}
\value{
A character vector of positive length, containing the file paths
that matched \code{\dots}, or the empty string, \code{""}, if none
matched (unless \code{mustWork = TRUE}).
If matching the root of a package, there is no trailing separator.
\code{system.file()} with no arguments gives the root of the
\pkg{base} package.
}
\description{
Finds the full file names of files in packages etc.
}
\details{
This checks the existence of the specified files with
\code{\link[base]{file.exists}}. So file paths are only returned if there
are sufficient permissions to establish their existence.
The unnamed arguments in \code{...} are usually character strings, but
if character vectors they are recycled to the same length.
This uses \code{\link[base]{find.package}} to find the package, and hence
with the default \code{lib.loc = NULL} looks first for attached
packages then in each library listed in \code{\link[base]{.libPaths}()}.
Note that if a namespace is loaded but the package is not attached,
this will look only on \code{\link[base]{.libPaths}()}.
}
\examples{
pkg_sys()
}
\seealso{
\code{\link[base]{R.home}} for the root directory of the \R
installation, \code{\link[base]{list.files}}.
\code{\link[base]{Sys.glob}} to find paths via wildcards.
}
......@@ -15,8 +15,8 @@ render_report(
render_reports(
reports_dir = "./reports",
reports = list.files(reports_dir, pattern = "^[0-9]{2}-.*$"),
publish_dir = "./public/reports",
reports = list.dirs(reports_dir),
publish_dir = "../../public/reports",
...
)
}
......@@ -43,7 +43,8 @@ used (possibly not specified, either, in which case a directory name
\item{reports}{\link{character} subfolders containing each report}
\item{publish_dir}{\link{character} rendering output path}
\item{publish_dir}{\link{character} rendering output path relatively to the report
folder which is in format \code{"./reports/my_report"}}
}
\value{
\code{NULL}, this function is used for side effect.
......
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/use_reports.R
\name{use_reports}
\alias{use_reports}
\title{Set reports folder structure}
\usage{
use_reports(path = ".", overwrite = FALSE)
}
\arguments{
\item{path}{Destination folder for reports and templates}
\item{overwrite}{Allow overwriting templates folder}
}
\value{
Use for side effect.
}
\description{
Set reports folder structure
}
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