Skip to content

Commit

Permalink
#17 from jhrcook/bookdown
Browse files Browse the repository at this point in the history
Convert site to bookdown format
  • Loading branch information
jhrcook authored Feb 9, 2022
2 parents 44cbc5e + d212d5c commit e87bcda
Show file tree
Hide file tree
Showing 453 changed files with 41,368 additions and 193,566 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,6 @@ po/*~
/*_files/

# End of https://www.toptal.com/developers/gitignore/api/macos,python,r,jupyternotebooks

_main.rds
bookdown.rds
13 changes: 3 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,7 @@ SHELL=/bin/bash
help:
@echo "available commands"
@echo " - help : information about available commands"
@echo " - render : render the distill website"
@echo " - notebooks : run Notes and Assignment Rmd"
@echo " - build : run all Rmd and render the site"
@echo " - book : run all notebooks and build the gitbook"

render:
Rscript -e "rmarkdown::render_site()" && rm -r docs/data

notebooks:
Rscript run-all-notebooks.R

build: notebooks render
book:
Rscript -e 'bookdown::render_book("index.Rmd", "bookdown::gitbook")'
File renamed without changes.
File renamed without changes.
67 changes: 67 additions & 0 deletions _bookdown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
title: "Notes for the Bayesian Data Analysis course"
author: "Joshua Cook"
description: "My notes and work for the Bayesian Data Analysis course taught by Aki Vehtari."
book_filename: bookdown

url: 'https://jhrcook.github.io/bayesian-data-analysis-course/'
github-repo: 'hrcook/bayesian-data-analysis-course'
twitter-handle: 'joshdoesa'

date: "`r Sys.Date()`"

documentclass: book
new_session: yes
delete_merged_file: true
edit: https://github.com/jhrcook/bayesian-data-analysis-course/blob/master/%s
view: https://github.com/jhrcook/bayesian-data-analysis-course/blob/master/%s

before_chapter_script: ["src/globals.R"]

output_dir: "docs"

rmd_files: [
"index.Rmd",

"notes-intro.Rmd",
"notes-01_introduction_bda3-01.Rmd",
"notes-02_basics-of-Bayesian-inference_bda3-02.Rmd",
"notes-03_multidimensional-posterior_bda3-03.Rmd",
"notes-04_monte-carlo_bda3-10.Rmd",
"notes-05_mcmc_bda3-11.Rmd",
"notes-06_hmc-nuts-stan_bda3-12.Rmd",
"notes-07_hierarchical-models_bda3-5.Rmd",
"notes-08_model-checking-and-cv_bda3-6-7.Rmd",
"notes-09_model-selection_bda3-7.Rmd",
"notes-10_decision-analysis_bda3-9.Rmd",
"notes-11_normal-approx-freq-properties_bda3-04.Rmd",
"notes-12_extended-topics.Rmd",
"notes-13_intro-to-regression-models_bda3-14.Rmd",
"notes-14_hierarchical-linear-models_bda3-15.Rmd",
"notes-17_parametric-nonlinear-models_bda3-19.Rmd",
"notes-18_basis-function-models_bda3-20.Rmd",
"notes-19_gaussian-processes_bda3-21.Rmd",
"notes-20_finite-mixture-models_bda3-22.Rmd",
"notes-21_Dirichlet-process-models_bda3-23.Rmd",

"assignment_intro.Rmd",
"assignment-01.Rmd",
"assignment-02.Rmd",
"assignment-03.Rmd",
"assignment-04.Rmd",
"assignment-05.Rmd",
"assignment-06.Rmd",
"assignment-07.Rmd",
"assignment-08.Rmd",
"assignment-09.Rmd",

"exercises_intro.Rmd",
"exercises-01.Rmd",
"exercises-02.Rmd",
"exercises-07.Rmd",
"exercises-19.Rmd",

"stan_models.Rmd",

"about.Rmd",
"references.Rmd"
]
54 changes: 54 additions & 0 deletions _generate_models_notebook.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env Rscript

library(glue)

# ---- Configuration ----

# Directory contains the Stan models.
MODELS_DIR <- file.path("models")
# Name of the notebook to generate.
OUTPUT_RMD_FILE <- file.path("stan_models.Rmd")

# ----

stan_model_files <- list.files(
MODELS_DIR,
pattern = "stan$",
full.names = TRUE,
recursive = FALSE,
ignore.case = TRUE
)
stan_model_files <- sort(stan_model_files)
cat(glue("number Stan models: {length(stan_model_files)}"), "\n")

stan_model_to_markdown <- function(model_file) {
model_txt <- readLines(model_file)
model_txt <- paste(model_txt, collapse = "\n")
md_txt <- "
## Model: `{basename(model_file)}`
```stan
{model_txt}
```
"
return(glue(md_txt))
}

rmd_text <- "# (PART) Models {-}
# Stan models
Below are the Stan models built as a part of this course.
The original files are available in the GitHub repo in the \"models\" directory.
"

for (mdl_file in stan_model_files) {
model_md <- stan_model_to_markdown(mdl_file)
rmd_text <- paste(rmd_text, model_md, sep = "\n")
}

rmd_text <- paste(rmd_text, "\n")
writeLines(rmd_text, OUTPUT_RMD_FILE)
cat(glue("output: {OUTPUT_RMD_FILE}"), "\n")
File renamed without changes.
17 changes: 17 additions & 0 deletions _output.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
bookdown::gitbook:
config:
toc:
collapse: section
before: |
<li><strong><a href="./">Notes for BDA3</a></strong></li>
after: |
<li><a href="https://github.com/rstudio/bookdown" target="_blank">Published with bookdown</a></li>
search:
engine: fuse
edit:
link: https://github.com/hadley/r4ds/edit/master/%s
text: "Edit"
sharing:
github: true
twitter: true
facebook: false
88 changes: 0 additions & 88 deletions _site.yml

This file was deleted.

22 changes: 11 additions & 11 deletions about.Rmd
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
---
title: "About"
description: |
Some additional details about this website and it's author.
---
# (PART) Misc {-}

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
# About {-}

## The website

This site is built with ['distill'](https://rstudio.github.io/distill/) and deployed on GitHub pages.
The main point of the website is to display my course notes in a easy to read and search format.
It isn't perfect nor optimal, but there is a good balance of functionality and simplicity.
The purpose of this website is to serve as a resource for using my notes and work for this course in the future.
Originally, I built it using ['distill'](https://rstudio.github.io/distill/) and deployed it as a simple static website on GitHub.
This worked well and was quick to build because the notebooks did not need to be re-run each time.
Though it is a very flexible platform, it had some limitations and I didn't like the styling of the notebooks in HTML.
I'm sure this could have been endlessly adjusted in CSS, but I realized firs that the ['bookdown'](https://pkgs.rstudio.com/bookdown/) format may be more appropriate for my needs.

I transformed this site into a 'bookdown' book after completing the course.
It took a bit of rearrangement, but I think the product is more logical and easier to use.
It has replaced the 'distill' website completely and is deployed on GitHub.

## About me

Expand Down
22 changes: 12 additions & 10 deletions assignments/jhcook-assignment-01.Rmd → assignment-01.Rmd
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
---
title: "Assignment 1"
date: "2021-08-19"
output: distill::distill_article
---
# Assignment 1

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, comment = "#>", dpi = 300)
```
2021-08-19

**[Assignment 1](assignment-01.pdf)**
**[Assignment 1](`r paste0(CM_URL, "assignment-01.pdf")`)**

## Setup

```{r}
```{r setup, warning=FALSE, message=FALSE}
knitr::opts_chunk$set(echo = TRUE, comment = "#>", dpi = 300)
library(glue)
```

Expand Down Expand Up @@ -238,3 +234,9 @@ stopifnot(round(p_identical_twin(1 / 100, 1 / 500), 7) == 0.2857143)
p_identical_twin(fraternal_prob = 1 / 150, identical_prob = 1 / 400)
```

---

```{r}
sessionInfo()
```
22 changes: 12 additions & 10 deletions docs/assignments/jhcook-assignment-02.Rmd → assignment-02.Rmd
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
---
title: "Assignment 2"
date: "2021-08-30"
output: distill::distill_article
---
# Assignment 2

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, comment = "#>", dpi = 300)
```
2021-08-30

**[Assignment 2](assignment-02.pdf)**
**[Assignment 2](`r paste0(CM_URL, "assignment-02.pdf")`)**

## Setup

```{r, warning=FALSE, message=FALSE}
```{r setup, warning=FALSE, message=FALSE}
knitr::opts_chunk$set(echo = TRUE, comment = "#>", dpi = 300)
for (f in list.files(here::here("src"), pattern = "R$", full.names = TRUE)) {
source(f)
}
Expand Down Expand Up @@ -173,3 +169,9 @@ posteriors %>%

The posterior is not very sensitive to the prior save for the exception of an overly-confident prior of $\text{Beta}(20, 100)$.
This is likely due to the large amount of data, meaning that the likelihood dominated the posterior.

---

```{r}
sessionInfo()
```
Loading

0 comments on commit e87bcda

Please sign in to comment.