Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add run_pipeline() first draft #149

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Authors@R: c(
comment = c(ORCID = "0000-0002-4094-1476")),
person("Thibaut", "Jombart", role = "aut"),
person("Carmen", "Tamayo", role = "aut", comment = c(ORCID = "0000-0003-4184-2864")),
person("Karim", "Mané", role = "aut", comment = c(ORCID = "0000-0002-9892-2999")),
person("data.org", role = "fnd")
)
Description: A store of outbreak analytics pipelines using different
Expand All @@ -16,7 +17,9 @@ URL: https://epiverse-trace.github.io/episoap,
BugReports: https://github.com/epiverse-trace/episoap/issues
Imports:
renv (>= 0.13.0),
rmarkdown
rmarkdown,
withr,
xfun
Suggests:
knitr,
spelling,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Generated by roxygen2: do not edit by hand

export(list_templates)
export(run_pipeline)
65 changes: 65 additions & 0 deletions R/run_pipeline.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#' Create report from template
#'
#' @param report A character vector of report template(s) to render (default to all

Check warning on line 3 in R/run_pipeline.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/run_pipeline.R,line=3,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 83 characters.
#' templates)
#' @param out_dir A character vector with the output directory (default to an
#' `episoap_report` in the current directory
#' @param preview A logical (default `TRUE`) indicating whether the rendered
#' report should be opened in the default browser
#' @param ... Arguments passed as parameters to the report template(s)
#'
#' @returns (invisibly) a character vector of paths to the rendered reports
#'
#' @export
#'
#' @examples
#' # Download data we need for this example
#' wd <- file.path(tempdir(), "episoap_report")
#' dir.create(wd)
#' download.file(
#' "https://github.com/epiverse-trace/episoap/blob/main/inst/rmarkdown/templates/transmissibility/skeleton/data/covid_linelist_england.rds?raw=true",

Check warning on line 20 in R/run_pipeline.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/run_pipeline.R,line=20,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 151 characters.
#' file.path(wd, "covid_linelist_england.rds")
#' )
#' # Running the pipeline with custom data saved on your computer
#' run_pipeline(
#' report = "transmissibility",
#' out_dir = wd,
#' # this is passed as a rmarkdown parameter to the report
#' data_file = "covid_linelist_england.rds"
#' )
run_pipeline <- function(
report = list_templates(),
out_dir = "episoap_report",
preview = TRUE,
...
) {

if (!dir.exists(out_dir)) {
dir.create(out_dir, recursive = TRUE)
}

withr::local_dir(out_dir)

report <- match.arg(report, several.ok = TRUE)

rendered <- vapply(report, function(r) {
rmarkdown::draft(
file = paste0(r, ".Rmd"),
template = r,
create_dir = FALSE,
package = "episoap",
edit = FALSE
)
# We run in a new session the prevent renv to leak in the user's environment
xfun::Rscript_call(
rmarkdown::render,
list(input = paste0(r, ".Rmd"), params = list(...))
)
}, character(1))

if (preview) {
utils::browseURL(rendered[[1]])
}

return(invisible(rendered))
}
47 changes: 47 additions & 0 deletions man/run_pipeline.Rd

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

9 changes: 9 additions & 0 deletions vignettes/design.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ knitr::opts_chunk$set(

As always during software development, we were faced with tough design choices while developing this package. We want to clearly document which choices were made, and what are the reasons behind them.

## Report parameters

### Names

As much as possible, parameter names should be re-used across reports. This allows us to:

- provide a consistent user experience
- pass a common set of arguments in a potential wrapper function that would render multiple reports at once

## Package and version management

Breaking changes during R package updates in one of the major sources of non-[reproducibility](https://cran.r-project.org/web/views/ReproducibleResearch.html) and of headaches for R users of all levels. To guard users against this, but also to ensure that the provided templates work out of the box, throughout the time a given `{episoap}` version is on CRAN, we [pin specific versions for our dependencies](https://cloud.google.com/blog/topics/developers-practitioners/best-practices-dependency-management), via `{renv}`.
Expand Down
Loading