Verified Commit 6386122b authored by Renato Alves's avatar Renato Alves 🌱
Browse files

Add article on building R Markdown reports from the command-line

parent 5c828aa8
Pipeline #28571 passed with stages
in 36 seconds
date: 2022-01-11
featured_image: "/images/2022-01-11/fotis-fotopoulos-DuHKoV44prg-unsplash.jpg"
tags: ["Renato Alves", "R", "RStudio", "Markdown", "SLURM", "Bio-IT", "EMBL"]
title: "Building R Markdown reports without RStudio"
omit_header_text: true
[RStudio][rstudio] is a powerful and user-friendly platform for developing and performing R based data analysis.
Coupled with [R Markdown][], one can easily generate visually rich reports that are one of, if not the, most used feature by the R community at EMBL to communicate results.
When the popular [GBCS][gbcs] [RStudio server][embl-rstudio] backed by the [large `seneca` server][seneca] is too busy, or if you need a convenient way to generate R Markdown reports in parallel or as part of elaborate pipelines,
you can use the following script:
#!/usr/bin/env bash
if [ "2" -gt "$#" ]; then
echo "Usage: $0 script.Rmd path/to/output.html arg1=\'value1\' arg2=\'value2\' ..."
exit 1
function commas() { local IFS=","; echo "$*"; }
OUTNAME="$(basename "$1")"
OUTDIR="$(dirname "$1")"
echo "Running: R -e \"rmarkdown::render('$FILE',output_format='html_document',output_dir='${OUTDIR}',output_file='${OUTNAME}',params=list($(commas "$@")))\""
R -e "rmarkdown::render('$FILE',output_format='html_document',output_dir='${OUTDIR}',output_file='${OUTNAME}',params=list($(commas "$@")))"
saving the above content on a file called `Rmarkdown` and adding it to your shell's `$PATH` will allow you to execute
Rmarkdown my_analysis.Rmd output_folder/output.html arg1='value1' arg2='value2'
and build or knit R Markdown reports without RStudio.
To use the above command with the EMBL cluster, don't forget to load the appropriate R `module` (e.g. `module add R-bundle-Bioconductor-GBCS/3.11-foss-2020a-R-4.0.0`) beforehand.
Happy reporting!
Photo by [Fotis Fotopoulos](
on [Unsplash](
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment