Skip to contents

Render RMarkdown document for a stage of the pipeline.

Usage

generate_stage_report(
  rmd_file,
  out_html_file_name,
  output_dir = fs::path_dir(out_html_file_name),
  css_file = here("Rmd/common/stylesheet.css"),
  params = list(),
  message = TRUE,
  warning = TRUE,
  echo = TRUE,
  quiet = TRUE,
  other_deps = NULL,
  drake_cache_dir = here(".drake"),
  ...
)

Arguments

rmd_file

A character scalar: path to Rmd file to render.

out_html_file_name

A character scalar: name of the output HTML file.

output_dir

A character scalar: path to directory in which out_html_file_name will be created. This directory will be created if it does not exist.

css_file

A character scalar: path to CSS file which will be included in the resulting HTML.

params

A list of RMarkdown document parameters: passed to rmarkdown::render() together with css_file and drake_cache_dir items.

message, warning, echo

A logical scalar: passed to knitr::opts_chunk$set().

quiet

A logical scalar: if TRUE, do not be verbose during rendering. Passed to rmarkdown::render().

other_deps

A list of symbols (unquoted): used inside drake::plan() to mark other target dependencies, which are not loaded (drake::loadd()) or read (drake::loadd()) inside the rmd_file.

drake_cache_dir

A character scalar: path to drake cache directory.

...

Passed to rmarkdown::render().

Value

Invisibly NULL.

Details

If you are currently working within a scdrake project, you can review the Rmd files in the Rmd/ directory.

This is a list of Rmd files currently bundled with the scdrake package:

fs::dir_tree(system.file("Rmd", package = "scdrake"))
#> /home/rstudio/scdrake_source/inst/Rmd
#> +-- common
#> |   +-- _footer.Rmd
#> |   +-- _header.Rmd
#> |   +-- cluster_markers.Rmd
#> |   +-- cluster_markers_table_template.Rmd
#> |   +-- clustering
#> |   |   +-- cluster_graph_leiden.Rmd
#> |   |   +-- cluster_graph_louvain.Rmd
#> |   |   +-- cluster_graph_walktrap.Rmd
#> |   |   +-- cluster_kmeans.Rmd
#> |   |   +-- cluster_sc3.Rmd
#> |   |   \-- clustering.Rmd
#> |   +-- contrasts.Rmd
#> |   +-- contrasts_table_template.Rmd
#> |   \-- stylesheet.css
#> +-- integration
#> |   +-- 01_integration.Rmd
#> |   \-- 02_int_clustering.Rmd
#> \-- single_sample
#>     +-- 01_input_qc.Rmd
#>     +-- 01_input_qc_children
#>     |   +-- cell_filtering_custom.Rmd
#>     |   +-- cell_filtering_qc.Rmd
#>     |   +-- empty_droplets.Rmd
#>     |   +-- empty_droplets_spat.Rmd
#>     |   +-- gene_filtering_custom.Rmd
#>     |   \-- gene_filtering_qc.Rmd
#>     +-- 01_input_qc_spatial.Rmd
#>     +-- 02_norm_clustering.Rmd
#>     \-- 02_norm_clustering_simple.Rmd

A short description of these Rmd files:

  • Common to single-sample and integration analyses:

    • Cluster markers: common/cluster_markers.Rmd (signpost), common/cluster_markers_table_template.Rmd (actual table with markers)

    • Contrasts: common/cluster_markers.Rmd, common/cluster_markers_table_template.Rmd

  • Single-sample analysis:

    • Input QC: single_sample/01_input_qc.Rmd. Input data overview, empty droplets detection, cell and gene filtering visualization.

    • Normalization and clustering: single_sample/02_norm_clustering.Rmd, single_sample/02_norm_clustering_simple.Rmd (only clustering visualization - dimred plots). Overview of normalization and highly variable genes selection, doublet score plots, selection of principal components, clustering diagnostics, dimred plots of clusterings and other variables.

  • Integration analysis:

    • Integration: integration/01_integration.Rmd. Overview of input datasets, highly variable genes selection, selection of principal components, dimred plots of integration, integration diagnostics.

    • Clustering: integration/02_int_clustering.Rmd. Clustering diagnostics, dimred plots of clusterings and other variables.

All Rmd files are also accompanied with a list of config parameters and runtime information.

Working with Rmd files outside of a plan

Each Rmd file for a stage can be rendered (with generate_stage_report(), not rmarkdown::render() - see below), or run interactively in RStudio, both outside of a drake plan. However, this assumes:

  • Your working directory is in the root of a scdrake project.

  • For interactive usage in RStudio, set Options -> R Markdown -> Basic -> Evaluate chunks in directory to "Project". Otherwise the working directory will be in the location of a Rmd file while running R code chunks. Also, all Rmd files are parametrized, i.e. they are referencing a params list, which is passed to rmarkdown::render() by generate_stage_report(). In order for code chunks to work properly, you have to create a variable named params_ (it must be available in the global environment) containing a named list. Currently, this list must contain only a single item: drake_cache_dir with path to drake cache which will be used to load targets inside the Rmd files. Example: params_ <- list(drake_cache_dir = ".drake_my_analysis")

NOTE: It is not recommended to call rmarkdown::render() directly on a stage's Rmd file, because generate_stage_report() also sets some temporary options and passes a proper params parameter.

Examples

if (FALSE) {
generate_stage_report(
  rmd_file = here("Rmd/single_sample/01_input_qc.Rmd"),
  out_html_file_name = "01_input_qc.html",
  output_dir = here("my_output"),
  drake_cache_dir = here(".drake_cache")
)
}