build xaringan slides with snakemake

public public 1yr ago 0 bookmarks

TLDR:

  1. Install R, Snakemake and xaringan.

  2. Navigate to this project's directory and then run: snakemake all --cores 1

    • End result is a html and pdf presentation

Introduction

Repository provides a template to build xaringan presentations to html and pdf using the Snakemake workflow management system. I also manage R's package dependencies with renv .

Motivating Example

I use the Rmarkdown file slides.Rmd which contains the slide template that you would get if you created a new xaringan presentation in RStudio.

Installation Instructions

Follow these Steps to install the necessary software on your system

You need to have the following software and packages installed:

  1. Python 3 (Python 3.6 or higher)

  2. Snakemake (we'll install it in a couple of lines time!)

  3. R (version 4.0.x)

Installing Python

Either:

  1. Install Anaconda Python:

    • We provide instructions on how to install anaconda python here
  2. Install Python using the deadsnakes ppa (Debian/Ubuntu flavored):

    • Here's how to add the deadsnakes ppa and install Python 3.8
    $ sudo apt-get install software-properties-common
    $ sudo add-apt-repository ppa:deadsnakes/ppa
    $ sudo apt-get update
    $ sudo apt-get install python3.8
    

Installing Snakemake

I have included a requirements.txt file that we can use to install a specific version of snakemake. This makes sure that my example runs on your machine (or at least won't break because you use a different version of snakemake than I do)

pip3 install -r requirements.txt

you may need to replace pip3 with pip

Installing R

We provide instructions on how to install R here

Installing xaringan

Either:

  1. Install it using install.packages('xaringan') in the R console

  2. Use our renv workflow:

Open a terminal and navigate to this directory. Then in the terminal enter the following command to install renv:

snakemake --cores 1 renv_install

Then you will need to provide consent for renv to be able to write files to your system:

snakemake --cores 1 renv_consent

Once this is complete you can use renv to create a separate R environment that contains the packages we use in our example by entering the following command into the terminal:

snakemake --cores 1 renv_init

The above command will initialize a separate R environment for this project.

Now we will install the necessary packages (and their precise versions) which are stored in the renv.lock file:

snakemake --cores 1 renv_restore

This will install all the packages we need. It may take a while.

Running the Example:

Navigate to this project's directory, and then run the following command in the terminal:

If you want html and pdf slides:

$ snakemake all --cores 1

If you only want the html presentation:

$ snakemake build_html --cores 1

To get the pdf (you need the html), so use snakemake all --cores 1

Updates to Workflow Example

Major changes are tracked in the NEWS file with brief descriptions of the changes implemented.

Comments / Suggestions / Issues

I'd love to hear your comments, suggestions or installation issues encountered when running the example. Post an issue on Github.

Suggested Citation

Deer, Lachlan. 2021. Building Xaringan Presentations with Snakemake. url = "https://github.com/lachlandeer/xaringan-snakemake"

Code Snippets

11
12
shell:
    "{runR} install_renv.R"
SnakeMake From line 11 of rules/renv.smk
16
17
shell:
    "R -e 'renv::consent(provided = TRUE)'"
SnakeMake From line 16 of rules/renv.smk
21
22
shell:
    "R -e 'renv::init()'"
SnakeMake From line 21 of rules/renv.smk
26
27
shell:
    "R -e 'renv::snapshot()'"
SnakeMake From line 26 of rules/renv.smk
31
32
shell:
    "R -e 'renv::restore()'"
SnakeMake From line 31 of rules/renv.smk
24
25
26
shell:
    "{run_r} {input.runner} {input.slides} \
                {output.slides} > {log} {log_all}"
37
38
39
shell:
    "{run_r} {input.runner} {input.slides} \
                {output.slides} > {log} {log_all}"
49
50
shell: 
    "rm *.pdf *.html"
ShowHide 8 more snippets with no or duplicated tags.

Login to post a comment if you would like to share your experience with this workflow.

Do you know this workflow well? If so, you can request seller status , and start supporting this workflow.

Free

Created: 1yr ago
Updated: 1yr ago
Maitainers: public
URL: https://github.com/lachlandeer/xaringan-snakemake
Name: xaringan-snakemake
Version: 1
Badge:
workflow icon

Insert copied code into your website to add a link to this workflow.

Downloaded: 0
Copyright: Public Domain
License: None
Keywords:
  • Future updates

Related Workflows

cellranger-snakemake-gke
snakemake workflow to run cellranger on a given bucket using gke.
A Snakemake workflow for running cellranger on a given bucket using Google Kubernetes Engine. The usage of this workflow ...