Skip to content

Commit

Permalink
Merge pull request #79 from reconhub/fix77
Browse files Browse the repository at this point in the history
change argument ordering (closes #77)
  • Loading branch information
thibautjombart authored Mar 8, 2021
2 parents bce7e7e + a499027 commit 6dcf954
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 31 deletions.
11 changes: 10 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
# reportfactory (development version)

## Bug fixes
* Fixes (#74) where files generated within the Rmd were not being copied
over to the output folder.

## Breaking changes
* Following user feedback `compile_reports()` now takes `reports` as a first
argument and `factory` as the second (previously these were the other way
round).

# reportfactory 0.1.3

* Implements slighlty less strict folder validation.
* Implements slightly less strict folder validation.
* Fix for CRAN. One additional test skipped on macs.

# reportfactory 0.1.2
Expand Down
6 changes: 3 additions & 3 deletions R/compile_reports.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#' Compile one or several R Markdown reports
#'
#' @param factory The path to the report factory or a folder within the desired
#' factory. Defaults to the current directory.
#' @param reports Either a regular expression (passed directly to `grep()`) that
#' matches to the report paths you would like to compile or an integer/logical
#' vector. If `reports` is an integer or logical vector then a call of
#' `compile_reports(factory, reports = idx)` is equivalent to
#' `compile_reports(factory, list_reports(factory)[idx])`.
#' @param factory The path to the report factory or a folder within the desired
#' factory. Defaults to the current directory.
#' @param params A named list of parameters to be used for compiling reports,
#' passed to `rmarkdown::render()` as the params argument. Values specified
#' here will take precedence over default values specified in YAML headers of
Expand All @@ -31,7 +31,7 @@
#'
#' @importFrom utils write.table
#' @export
compile_reports <- function(factory = ".", reports = NULL,
compile_reports <- function(reports = NULL, factory = ".",
params = NULL, quiet = TRUE, subfolder = NULL,
timestamp = format(Sys.time(), "%Y-%m-%d_T%H-%M-%S"),
...) {
Expand Down
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,16 @@ always clear what will be built.
compile_reports(
reports = "example_report.Rmd"
)
#> >>> Compiling report: /example_report
#> >>> Compiling report: example_report
#> All done!
```

Use `list_ouputs()` to view the report outputs.

``` r
list_outputs()
#> [1] "example_report/2021-01-21_T10-44-57/example_report.html"
#> [2] "example_report/2021-01-21_T10-44-57/example_report.Rmd"
#> [1] "example_report/2021-03-08_T09-16-24/example_report.html"
#> [2] "example_report/2021-03-08_T09-16-24/example_report.Rmd"
```

`compile_reports()` can also be used to pass a set of parameters to use
Expand All @@ -147,14 +147,14 @@ compile_reports(
params = list(grouped_plot = FALSE),
subfolder = "regional"
)
#> >>> Compiling report: /example_report
#> >>> Compiling report: example_report
#> - with parameters: grouped_plot = FALSE
#> All done!
list_outputs()
#> [1] "example_report/2021-01-21_T10-44-57/example_report.html"
#> [2] "example_report/2021-01-21_T10-44-57/example_report.Rmd"
#> [3] "example_report/regional/2021-01-21_T10-44-58/example_report.html"
#> [4] "example_report/regional/2021-01-21_T10-44-58/example_report.Rmd"
#> [1] "example_report/2021-03-08_T09-16-24/example_report.html"
#> [2] "example_report/2021-03-08_T09-16-24/example_report.Rmd"
#> [3] "example_report/regional/2021-03-08_T09-16-25/example_report.html"
#> [4] "example_report/regional/2021-03-08_T09-16-25/example_report.Rmd"
```

Note that reports can also be an integer or a logical vector, in which
Expand All @@ -172,7 +172,7 @@ the `factory_overview()` function:

``` r
factory_overview()
#> /tmp/Rtmp1gGdYE/my_factory
#> /tmp/RtmpWSy7OS/my_factory
#> ├── README.md
#> ├── data
#> │ ├── clean
Expand All @@ -181,11 +181,11 @@ factory_overview()
#> ├── factory_config
#> ├── outputs
#> │ └── example_report
#> │ ├── 2021-01-21_T10-44-57
#> │ ├── 2021-03-08_T09-16-24
#> │ │ ├── example_report.Rmd
#> │ │ └── example_report.html
#> │ └── regional
#> │ └── 2021-01-21_T10-44-58
#> │ └── 2021-03-08_T09-16-25
#> │ ├── example_report.Rmd
#> │ └── example_report.html
#> ├── report_sources
Expand Down
8 changes: 4 additions & 4 deletions man/compile_reports.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions tests/testthat/test-compile_reports.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ test_that("test parameteriesed report output", {

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

Expand Down Expand Up @@ -49,8 +49,8 @@ test_that("test output folder gets recreated if not there", {

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

Expand Down Expand Up @@ -78,8 +78,8 @@ test_that("parameteriesed report with missing param output but input", {

# compile report
compile_reports(
f,
"parameterised",
f,
params = list(test2 = "four", test3 = "five")
)

Expand All @@ -106,8 +106,8 @@ test_that("non parameteriesed report with param input", {

# compile report
compile_reports(
f,
"simple",
f,
params = list(test2 = "four", test3 = "five")
)

Expand Down Expand Up @@ -136,8 +136,8 @@ test_that("parameteriesed report with missing param (but in environment)", {

# compile report
compile_reports(
f,
"parameterised"
"parameterised",
f
)

# check the output
Expand Down Expand Up @@ -174,7 +174,7 @@ test_that("integer index for reports", {

# compile report
idx <- c(1, 3)
compile_reports(f, idx, timestamp = "test")
compile_reports(idx, f, timestamp = "test")
nms <- path_ext_remove(list_reports(f))[idx]
nms <- paste(nms, collapse = "|")
expected_files <- c(
Expand Down Expand Up @@ -234,7 +234,7 @@ test_that("logical index for reports", {

# compile report
idx <- c(TRUE, FALSE)
compile_reports(f, idx, timestamp = "test")
compile_reports(idx, f, timestamp = "test")
nms <- path_ext_remove(list_reports(f))[idx]
nms <- paste(nms, collapse = "|")
expected_files <- c(
Expand Down Expand Up @@ -282,7 +282,7 @@ test_that("figures folders copied correctly reports", {
file_delete(path(f, "report_sources", "example_report.Rmd"))

# compile report
compile_reports(f, timestamp = "test")
compile_reports(factory = f, timestamp = "test")
nms <- path_ext_remove(list_reports(f))
nms <- paste(nms, collapse = "|")
expected_files <- c(
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-list_outputs.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test_that("list_output works with nested and unnested files", {
# remove the other example report
file_delete(path(f, "report_sources", "example_report.Rmd"))

compile_reports(f, timestamp = "test")
compile_reports(factory = f, timestamp = "test")
output_files <- list_outputs(f)
expected_files <- c(
file.path("simple", "test", "simple.Rmd"),
Expand Down Expand Up @@ -73,7 +73,7 @@ test_that("list_output works, one file compiled", {
nested_dir
)

compile_reports(f, "parameterised", timestamp = "test")
compile_reports(factory = f, "parameterised", timestamp = "test")
output_files <- list_outputs(f)
expected_files <- c(
file.path("nested", "parameterised", "test", "parameterised.Rmd"),
Expand Down Expand Up @@ -105,7 +105,7 @@ test_that("list_output works, with subfolders", {
nested_dir
)

compile_reports(f, "parameterised", timestamp = "test", subfolder = "bob")
compile_reports(factory = f, "parameterised", timestamp = "test", subfolder = "bob")
output_files <- list_outputs(f)
expected_files <- c(
file.path("nested", "parameterised", "bob", "test", "parameterised.Rmd"),
Expand Down

0 comments on commit 6dcf954

Please sign in to comment.