diff --git a/R/add_report.R b/R/add_report.R index 0593c77d8b8e6e5cb3db60d7eb49ad30e438d2ea..7db8e280cbff6a14b6b31b7e3e0c8c950c200120 100644 --- a/R/add_report.R +++ b/R/add_report.R @@ -10,10 +10,13 @@ #' #' @inherit create_reports examples #' -add_report <- function(name, template = "inrae", path = ".") { - if (!dir.exists(file.path(path, "reports"))) { +add_report <- function(name, template = "inrae", path = pkgload::pkg_path()) { + if (!all(dir.exists(file.path(path, c("reports", "templates"))))) { stop("Report structure not found, call `create_reports` first!") } + if (!dir.exists(file.path(path, "templates", template))) { + stop("Template\"", template, "\" not found in ", file.path(path, "templates")) + } destpath <- file.path(path, "reports", name) if (dir.exists(destpath)) stop("The folder ", diff --git a/man/add_report.Rd b/man/add_report.Rd index be5f79a341475c98aa990a1ea656d83cc6dca712..29b1dbeed1ecce0b47d3ec31cf8016b48e63fa23 100644 --- a/man/add_report.Rd +++ b/man/add_report.Rd @@ -4,7 +4,7 @@ \alias{add_report} \title{Add a new report in a fairify project} \usage{ -add_report(name, template = "inrae", path = ".") +add_report(name, template = "inrae", path = pkgload::pkg_path()) } \arguments{ \item{name}{Name of the report (sub-folder name in "reports")} diff --git a/tests/testthat/test-add_report.R b/tests/testthat/test-add_report.R index e487ea73c93f6075d58e90847098b38cef82a5d3..3396919ada50ecd1a2f3697b184b42d179168be7 100644 --- a/tests/testthat/test-add_report.R +++ b/tests/testthat/test-add_report.R @@ -2,6 +2,15 @@ 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 = path)) + unlink(path, recursive = TRUE) +}) + +test_that("add_report should raise error if template does not exists", { + path <- tempfile(pattern = "dir") + dir.create(path, recursive = TRUE) + create_reports(path) + expect_error(add_report("test", template = "wrong_template", path = path)) + unlink(path, recursive = TRUE) }) test_that("add_report should create a report", {