Skip to content
Joe Marlo edited this page Feb 1, 2023 · 20 revisions

thinkCausal wiki

Welcome to the thinkCausal wiki. thinkCausal is federally funded project devoted to building scaffolded causal inference software implementing Bayesian Additive Regression Trees. You can find a live, beta version here and a live version of the development branch here.

If you would like to contribute, please seeing the contributing guidelines.


Running the app in a local developer environment

Clone the repository to your machine use git clone in terminal. Run renv::restore() in R to download the dependencies. Run /thinkCausal/dev/run_dev.R script to launch the app.

To instead install the latest code as a package, use:

remotes::install_github('priism-center/thinkCausal_dev', subdir = 'thinkCausal')
thinkCausal::run_app()

Code guidelines

thinkCausal is a mix of 'base' R and tidyverse code. We try to adhere to the tidyverse style guide for code formatting. The easiest way to to format ~90% of your R code is Code -> Reformat Code within Rstudio.

We use roxygen2 for documenting functions and testthat for unit testing. Please familiarize yourself with both and feel free to reach out with an issue if you have any questions.

Independent lessons should be written as modules. See the wiki for details.


Dependencies

We use renv to manage dependencies. You can use renv::restore() to install all the necessary packages. Please limit adding additional packages. Do not add thinkCausal as a dependency even if renv suggests it.


Application structure

The application is built on R Shiny and uses the golem opinionated framework. Each page is its own Shiny module which enables it to have its own namespace.

golem

It is encouraged to read the golem site and the Engineering Shiny book to understand the framework. golem is an opinionated framework that builds shiny apps as R packages. Structuring your code as modules are highly encouraged.

At a minimum, be familiar with the thinkCausal/dev/02_dev.R script and thinkCausal/dev/run_dev.R. The former keeps a record of adding new modules, tests, functions, etc. The latter should be sourced when running the app for development purposes.

The store object

Any data that needs to passed between the main server and modules or between modules should be saved to the store object. This is equivalent to "stratégie du petit" in the Engineering Shiny book.

Branching model

master branch - Production branch. Is deployed on push/pull to apsta.shinyapps.io/thinkCausal
dev branch - Primary developer branch. Is deployed on push to apsta.shinyapps.io/thinkCausal-dev
gh-pages branch - Automatically created branch from the /_site@master folder that builds to a static website
{other} branch - Unique branches for new features or individual developer work

When adding a new feature, it is recommended to create your own branch and then PR into the dev. This will deploy the app to apsta.shinyapps.io/thinkCausal-dev/ for testing. Then PR from dev into master. For small fixes, working directly off the dev branch is recommended.

Directory structure

.
├── LICENSE
├── README.md
├── scratch/                  Scratch work
├── screenshot.png
├── _site/                    Static website that builds priism-center.github.io/thinkCausal_dev/
├── student_work/             Store for student's work
├── thinkCausal
│   ├── app.R                 App for pushing to shinapps.io
│   ├── DESCRIPTION
│   ├── dev/                  Scripts for developing the app via the `golem` framework
│   │   ├── 01_start.R
│   │   ├── 02_dev.R
│   │   ├── 03_deploy.R
│   │   └── run_dev.R
│   ├── inst/                 Content to build in the R package including the web application
│   │   ├── app
│   │   ├── extdata           Store for external data such as csvs
│   │   ├── golem-config.yml
│   │   ├── reproduce
│   │   └── WORDLIST
│   ├── LICENSE
│   ├── LICENSE.md
│   ├── man
│   ├── NAMESPACE
│   ├── R/                    All R functions and modules
│   ├── renv
│   ├── renv.lock
│   ├── tests
│   └── thinkCausal.Rproj
└── writing/                  Store for various writing such as vignette prototyping