-
Notifications
You must be signed in to change notification settings - Fork 1
/
_common.R
118 lines (105 loc) · 3.36 KB
/
_common.R
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
set.seed(5678)
options(
dplyr.width = Inf,
dplyr.print_min = 6,
dplyr.print_max = 6,
stringr.view_n = 10,
pillar.bold = TRUE,
width = 77 # 80 - 3 for #> comment
)
knitr::opts_chunk$set(
message = FALSE,
warning = FALSE,
comment = "#>",
fig.retina = 3,
fig.width = 6,
fig.height = 4,
fig.show = "hold",
fig.align = "center",
fig.path = "figs/"
)
get_schedule <- function() {
# Icons
# https://icons.getbootstrap.com/
# fa <- list(
# class = '<i class="bi-laptop-fill"></i>',
# assignment = '<i class="bi-pencil-fill"></i>',
# reading = '<i class="bi-book-fill"></i>'
# )
schedule_raw <- read_csv(here::here('schedule.csv'))
# Quiz vars
quiz <- schedule_raw %>%
mutate(
quiz = ifelse(
is.na(quiz),
"",
paste0('Quiz ', quiz, ":<br><em>", quiz_coverage, "</em>"))
) %>%
select(week, quiz)
# Weekly assignment vars
assignments <- schedule_raw %>%
mutate(
due_assign = format(due_assign, format = "%b %d"),
assignments = ifelse(
is.na(due_assign),
"",
paste0(
'<a href="hw/', n_assign, "-", stub_assign, '.html"><b>HW ',
n_assign, "</b></a><br>Due: ", due_assign))
) %>%
select(week, assignments)
# Class vars
class <- schedule_raw %>%
mutate(
description_class = ifelse(
is.na(description_class),
"",
description_class),
class = ifelse(
is.na(stub_class),
paste0("<b>", name_class, "</b><br>", description_class),
paste0(
'<a href="class/', n_class, "-", stub_class, '.html"><b>',
name_class, "</b></a><br> ",
description_class)),
) %>%
select(week, class)
# Reading vars
reading <- schedule_raw %>%
select(week, ends_with("_reading"), reading) %>%
rename(name = name_reading, stub = stub_reading) %>%
mutate(
name = str_split(name, '\n'),
stub = str_split(stub, '\n')
)
# Fix reading names
reading_root <- 'https://p4a.jhelvy.com/'
reading$readings <- ""
for (i in 1:nrow(reading)) {
name <- reading[i,]$name[[1]]
if (any(is.na(unlist(name)))) {
result <- ''
} else {
stub <- reading[i,]$stub[[1]]
result <- paste0(
'<a href=', reading_root, stub ,'.html target="_blank"><b>',
name, "</b></a>")
result <- paste(result, collapse = '<br>')
}
reading$readings[i] <- result
}
reading$name <- NULL
reading$stub <- NULL
reading <- reading %>%
mutate(readings = ifelse(!is.na(reading), reading, readings))
# Final schedule data frame
schedule <- schedule_raw %>%
select(week, date, n_assign, due_assign) %>%
mutate(date_md = format(date, format = "%b %d")) %>%
left_join(quiz, by = "week") %>%
left_join(class, by = "week") %>%
left_join(assignments, by = "week") %>%
left_join(reading, by = "week") %>%
ungroup()
return(schedule)
}