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

feat: add_report function

Refs #3
parent 52f4f9a4
No related branches found
No related tags found
No related merge requests found
......@@ -62,3 +62,4 @@ rsconnect/
/public
/reports
/templates
/.vscode
......@@ -2,6 +2,7 @@
export("%>%")
export(add_gitignore)
export(add_report)
export(create_fairify)
export(create_reports)
export(getDataPath)
......
#' Add a new report in a fairify project
#'
#' @param name Name of the report (sub-folder name in "reports")
#' @param path Path of the fairify project
#'
#' @return The path of the added report
#' @export
#'
#' @inherit create_reports examples
#'
add_report <- function(name, path = ".") {
if (!dir.exists(file.path(path, "reports"))) {
stop("Report structure not found, call `create_reports` first!")
}
destpath <- file.path(path, "reports", name)
if (dir.exists(destpath))
stop("The folder ",
destpath,
" exists already. Delete it first or choose another.")
b <- file.copy(
from = file.path(pkg_sys("bookdown_template")),
to = file.path(path, "reports"),
recursive = TRUE,
copy.date = TRUE
)
if (any(!b))
stop("The copy of the template report failed")
file.rename(
file.path(path, "reports", "bookdown_template"),
destpath
)
return(destpath)
}
......@@ -7,9 +7,14 @@
#' @export
#'
#' @examples
#' # Create structure for reports
#' path <- tempdir()
#' create_reports(path)
#' list.files(path, recursive = TRUE)
#'
#' # Add a new report
#' report_path <- add_report("my_report", path)
#' list.files(report_path)
create_reports <- function(path = ".", overwrite = FALSE) {
# Copy templates
if (dir.exists(file.path(path, "templates"))) {
......
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/add_report.R
\name{add_report}
\alias{add_report}
\title{Add a new report in a fairify project}
\usage{
add_report(name, path = ".")
}
\arguments{
\item{name}{Name of the report (sub-folder name in "reports")}
\item{path}{Path of the fairify project}
}
\value{
The path of the added report
}
\description{
Add a new report in a fairify project
}
\examples{
# Create structure for reports
path <- tempdir()
create_reports(path)
list.files(path, recursive = TRUE)
# Add a new report
report_path <- add_report("my_report", path)
list.files(report_path)
}
......@@ -18,7 +18,12 @@ Use for side effect.
Set reports folder structure
}
\examples{
# Create structure for reports
path <- tempdir()
create_reports(path)
list.files(path, recursive = TRUE)
# Add a new report
report_path <- add_report("my_report", path)
list.files(report_path)
}
test_that("add_report should raise error if reports does not exists", {
path <- tempfile(pattern = "dir")
dir.create(path, recursive = TRUE)
expect_error(add_report("test", path))
})
test_that("add_report should create a report", {
path <- tempfile(pattern = "dir")
dir.create(path, recursive = TRUE)
create_reports(path)
add_report("test", path)
expect_true(
all(file.exists(
file.path(path,
"reports/test",
list.files(pkg_sys("bookdown_template")))
)))
})
test_that("create_fairify works", {
path <- tempfile()
path <- tempfile(pattern = "dir")
create_fairify(path, open = FALSE)
project <- basename(path)
expect_true(file.exists(file.path(path, paste0(project, ".Rproj"))))
......@@ -7,7 +7,7 @@ test_that("create_fairify works", {
})
test_that("create_fairify with git = FALSE doesn't create git repoworks", {
path <- tempfile()
path <- tempfile(pattern = "dir")
create_fairify(path, open = FALSE, git = FALSE)
project <- basename(path)
expect_false(file.exists(file.path(path, ".git")))
......
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