-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_common.R
155 lines (129 loc) · 3.86 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
set.seed(5678)
# Load libraries and options
library(knitr)
library(here)
library(tidyverse)
library(fontawesome)
library(cowplot)
library(kableExtra)
library(lubridate)
options(dplyr.width = Inf)
options(knitr.kable.NA = '')
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/"
)
make_rubric <- function(rubric) {
rubric %>%
mutate(description = paste0("<b>", points, '</b><br>', description)) %>%
select(-points) %>%
spread(key = rating, value = description) %>%
select(-category) %>%
rename(Category = label) %>%
arrange(order) %>%
select(-order) %>%
select(-maxPoints) %>%
kable(format = 'html', escape = FALSE) %>%
kable_styling(bootstrap_options = "striped")
}
# The icon_link() function is in {distilltools}, but I've modified this
# one to include a custom class to be able to have more control over the
# CSS and an optional target argument
icon_link <- function(
icon = NULL,
text = NULL,
url = NULL,
class = "icon-link",
target = "_blank"
) {
if (!is.null(icon)) {
text <- make_icon_text(icon, text)
}
return(htmltools::a(
href = url, text, class = class, target = target, rel = "noopener"
))
}
make_icon_text <- function(icon, text) {
return(HTML(paste0(make_icon(icon), " ", text)))
}
make_icon <- function(icon) {
return(tag("i", list(class = icon)))
}
clean_schedule_name <- function(x) {
x <- x %>%
str_to_lower() %>%
str_replace_all(" & ", "-") %>%
str_replace_all(" ", "-")
return(x)
}
# Load custom functions
get_schedule <- function() {
# Get raw schedule
df <- read_csv(here::here('schedule.csv'))
# Quiz vars
quiz <- df %>%
mutate(
quiz = ifelse(
is.na(quiz),
"",
paste0('Quiz ', quiz, ":<br><em>", quiz_content, "</em>"))
) %>%
select(week, ends_with('quiz'))
# Class vars
class <- df %>%
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, ends_with('class'))
# Weekly assignment vars
assignments <- df %>%
mutate(
due_assign = format(due_assign, format = "%b %d"),
assign = ifelse(
is.na(due_assign),
name_assign,
paste0(
'<a href="hw/', n_assign, "-", stub_assign, '.html"><b>HW ',
n_assign, "</b></a><br>Due: ", due_assign))
) %>%
select(week, ends_with('assign'))
# Final project vars
project <- df %>%
mutate(
due_project = format(due_project, format = "%b %d"),
project = ifelse(
is.na(due_project),
"",
paste0(
'<a href="project/', n_project, "-", stub_project, '.html"><b>',
name_project, "</b></a><br>Due: ", due_project))
) %>%
select(week, ends_with('project'))
# Final schedule data frame
schedule <- df %>%
select(week, date) %>%
mutate(date_md = format(date, format = "%b %d")) %>%
left_join(class, by = "week") %>%
left_join(quiz, by = "week") %>%
left_join(assignments, by = "week") %>%
left_join(project, by = "week") %>%
ungroup()
return(schedule)
}