-
Notifications
You must be signed in to change notification settings - Fork 1
/
session_03_materials.Rmd
47 lines (38 loc) · 1.34 KB
/
session_03_materials.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
---
title: Session 3 — Materials
date: "August 1, 2018"
---
```{r include=FALSE}
knitr::opts_chunk$set(echo = FALSE, results = 'asis')
make_listing <- function(filename, path_rel, base_url = "https://gerkelab.github.io/core-r-course") {
cat(glue::glue('\n- [{filename}]({path_rel})\n\n ```\n download.file("{file.path(base_url, path_rel)}", "{filename}")\n ```\n\n'))
}
needs_zip <- function(zipfile, dirpath) {
zipfile <- here::here(dirpath, "..", zipfile)
if (!file.exists(zipfile)) return(TRUE)
zip_modtime <- fs::file_info(zipfile)$modification_time
files_modtime <- fs::file_info(fs::dir_ls(dirpath)) %>% pull(modification_time) %>% max()
zip_modtime < files_modtime
}
SESSION <- "03"
ZIPFILE <- glue::glue("core-r_session-{SESSION}_materials.zip")
SESSION_DIR <- file.path("materials", SESSION)
```
Materials for [Session 3](session_03.html).
## Zip File
```{r}
if (needs_zip(ZIPFILE, SESSION_DIR)) {
utils::zip(zipfile = file.path("materials", ZIPFILE),
files = file.path("materials", SESSION),
extras = "-x *.DS_Store")
}
make_listing(ZIPFILE, file.path("materials", ZIPFILE))
```
## Individual Files
```{r}
fs::file_info(fs::dir_ls(SESSION_DIR)) %>%
mutate(path_rel = fs::path_rel(path, here::here())) %>%
select(path_rel) %>%
mutate(filename = basename(path_rel)) %>%
purrr::pwalk(make_listing)
```