-
Notifications
You must be signed in to change notification settings - Fork 0
Reproducible R Projects with WorkflowR
NOTE: I highly recommend skipping this step for most projects nowadays as re-installing everything takes ages. Will use for projects where there is an important need to have everything be 100% reproducible.
- Create a new project as normal in RStudio (without git initialisation, as WorkflowR will create one later).
- Before writing any code, load the Packrat R package
library(packrat)
and initialise Packrat usingpackrat::init("~/pathTo/PROJECTNAME")
. Packrat is a library manager for R and RStudio that isolates the packages used to a particular project. This ensures that the exact packages and their versions that were used in a particular project can be carried in a modular way with the project, making it easy to reproduce. More information about Packrat can be found in their documentation. - After installing new packages with Packrat (using
install_packages()
), usepackrat::snapshot()
to save the changes.
We will use WorkflowR to manage and organise the directories and files for the project.
- Install workflowR and load the package using
library(workflowr)
. - Run the following in the Console to set up WorkflowR:
wflow_start("~/pathTo/PROJECTNAME", existing = TRUE, overwrite = TRUE)
- Run
wflow_build()
in the Console. - Build and commit the website using
wflow_publish()
.
Note: The status of files can be checked using wflow_status()
.
- To deploy the website, run the following in Console:
wflow_use_github("nhihin")
(replace with GitHub username) and select option 1 to automatically create the repository. NOTE: When you have to enter your password for this step, instead of your GitHub password, create a Personal Access Token here and enter the value of that token instead! This is because GitHub is deprecating the use of passwords directly by 3rd party programs (including RStudio), see here. - The Git tab on RStudio can now be used as normal to commit, push, and pull files. If it isn't showing up, usually restarting RStudio fixes this.
Note: If the GitHub repository needs to be private (e.g. sensitive/client data), this needs to be changed immediately after step 5 on the GitHub website, see here.
- Use
wflow_open("analysis/your-file-name.Rmd")
to make a new analysis RMarkdown. - Files must be committed using
wflow_build("analysis/your-file-name.Rmd")
and pushed usingwflow_publish("analysis/your-file-name.Rmd")
. - Globbing is useful for committing and pushing, for example,
wflow_build("analysis/*.Rmd")
will build all .Rmd files in the analysis directory.
- This is important to do early on, as the navigation bar defined will be used across every analysis file created. This saves time if defined early on.
- Open the file in
analysis/_site.yml
. - Under
left:
is where you can define links in the navigation bar.Text
is the name of the link whilehref
is the URL of the link. This is a relative url pointing to theanalysis
directory so no need to put in the full path. - Typically one link for one analysis file for each specific step of the analysis. The
menu:
thing is used to define a drop-down menu, which is helpful for organising many analysis pages which are related to each other.
Example:
name: Project Name
output_dir: ../docs
navbar:
title: Project Name
left:
- text: Home
href: index.html
- text: About
href: about.html
- text: Setup
href: setup.html
menu:
- text: "Pre-processing"
- text: "cellranger pipeline"
href: cellranger.html
- text: "Initial analysis"
- text: "Merge datasets with Seurat"
href: import-data.html
- text: "Aggregate with cellranger"
href: import-merged-data.html
- text: License
href: license.html
right:
- icon: fa-github
text: Source code
href: https://github.com/nhihin/Heart-scRNAseq
output:
workflowr::wflow_html:
toc: yes
toc_float: yes
theme: cosmo
highlight: textmate
- Once all RMarkdown files have been published as .html files (and pushed to GitHub using
wflow_publish
), go toSettings > GitHub Pages
and choose “master branch docs/ folder” as the Source. See screenshot below.
-
This will publish the files in
docs
undernhihin.github.io/myproject
(or the URL listed on GitHub Pages section of the Settings page). See https://jdblischak.github.io/workflowr/articles/wflow-01-getting-started.html#deploy-the-website for more details. -
Gitlab is an alternative way to deploying the website and having it hosted online. Instructions here: https://jdblischak.github.io/workflowr/articles/wflow-06-gitlab.html