Skip to content

Commit

Permalink
less strict checking for 'outputs' folder. Fixes #72
Browse files Browse the repository at this point in the history
  • Loading branch information
TimTaylor committed Feb 16, 2021
1 parent 0c256d6 commit b3ed129
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 23 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: reportfactory
Title: Lightweight Infrastructure for Handling Multiple R Markdown Documents
Version: 0.1.2.9
Version: 0.1.3
Authors@R: c(
person("Thibaut", "Jombart", role = "aut", email = "[email protected]"),
person("Amy", "Gimma", role = "ctb", email = "[email protected]"),
Expand Down
6 changes: 5 additions & 1 deletion R/compile_reports.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,12 @@ compile_reports <- function(factory = ".", reports = NULL,
}
}

# report output folder
# report output folder (create if it does not already exist)
report_output_dir <- file.path(root, outputs)
if (!dir.exists(report_output_dir)) {
dir.create(report_output_dir)
}

params_to_print <- params

# loop over all reports
Expand Down
19 changes: 8 additions & 11 deletions R/validate_factory.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' `validate_factory()` can be used to inspect the content of a factory and make
#' everything looks fine. This includes various sanity checks listed in details
#' that will error if a problem is found.
#'
#'
#' @inheritParams compile_reports
#'
#' @details
Expand All @@ -12,7 +12,7 @@
#' * the factory_config file exist;
#' * all mandatory folders exist - by default these are 'report_sources/'
#' and 'outputs/';
#'
#'
#' @return A list with 4 entries:
#' * root - the root folder path of the factory;
#' * factory_name - the name of the report factory;
Expand Down Expand Up @@ -44,9 +44,9 @@ validate_factory <- function(factory = ".") {
stop(
"Have you renamed the factory?\n",
sprintf(
"Expecting factory to be called '%s' not '%s'. Please rename",
"Expecting factory to be called '%s' not '%s'. Please rename",
factory_name,
folder
folder
),
call. = FALSE
)
Expand All @@ -73,7 +73,7 @@ validate_factory <- function(factory = ".") {
call. = FALSE
)
}

# outputs is present in factory_config
outputs <- config$outputs
if (is.null(outputs)) {
Expand All @@ -87,12 +87,9 @@ validate_factory <- function(factory = ".") {
# the outputs folder matches the name from factory_config
pth <- file.path(root, outputs)
if (!dir.exists(pth)) {
stop(
sprintf(
"Folder '%s' does not exist. Have you renamed it by mistake?",
outputs
),
call. = FALSE
message(
sprintf("Folder '%s' does not exist.", outputs),
" It will be created the first time 'compile_reports' is run"
)
}

Expand Down
15 changes: 7 additions & 8 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
Further to Brian Ripley's email on 21-01-2020 I have added a System
Requirement on Pandoc along with additional, user facing code, that errors
if it is not installed. Check's requiring pandoc are now skipped on Solaris.
## Reason for update
* minor bugfix/workflow improvement.
* resolves a failing test I noticed on the macos checks.

## Tested on
* Fedora 33, local R installation, R 4.0.3 (2020-10-10)
* Solaris via RHub (unsure of version but I believe it is the current release)
* Fedora 33, local R installation, (unstable) (2021-01-14 r79827)
* win-builder, R Under development (unstable) (2021-02-13 r80000)

### R CMD check results for above environments
0 errors | 0 warnings | 1 note
0 errors | 0 warnings | 0 note



Days since last update: 0

Hopefully this is ok as at request of Brian Ripley

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Testing parameterised reports
================

test parameter output

``` r
a <- params$test1
a
```

## [1] "three"

``` r
b <- params$test2
b
```

## [1] "four"
33 changes: 33 additions & 0 deletions tests/testthat/test-compile_reports.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,39 @@ test_that("test parameteriesed report output", {
})


test_that("test output folder gets recreated if not there", {
skip_if_pandoc_not_installed()
skip_on_os("windows")
skip_on_os("mac")

# create factory
f <- new_factory(path = path_temp(), move_in = FALSE)
on.exit(dir_delete(f))

# copy test reports over
file_copy(
path("test_reports", "parameterised.Rmd"),
path(f, "report_sources")
)

# delete outputs folder
file.remove(file.path(f, "outputs"))

# compile report
compile_reports(
f,
"parameterised",
params = list(test1 = "three", test2 = "four")
)

# check the output
md_file <- grep("\\.md", list_outputs(f), value = TRUE)
md_file <- path(f, "outputs", md_file)

expect_snapshot_file(md_file, "outputs_deleted_param_report_check.md", binary = FALSE)
})


test_that("parameteriesed report with missing param output but input", {
skip_if_pandoc_not_installed()
skip_on_os("windows")
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-validate_factory.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
library(fs)

test_that("validate factory - config tests", {

f <- new_factory(path = path_temp(), move_in = FALSE)
on.exit(dir_delete(f))
config_path <- path(f, "factory_config")
Expand Down Expand Up @@ -49,7 +49,7 @@ test_that("validate factory - config tests", {
tmp <- original_config
tmp$outputs = "bob"
write.dcf(tmp, config_path)
expect_error(
expect_message(
validate_factory(f),
"Folder 'bob' does not exist."
)
Expand Down

0 comments on commit b3ed129

Please sign in to comment.