-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.R
90 lines (74 loc) · 3.8 KB
/
init.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
library(tufte)
library(tidyverse)
library(knitr)
## functions --------------
##custom margin note wrangling function based on tufte::margin_note()
# number_column is a column of the dataframe that contains some sort of line number (needed so that unique labels are created for each margin note, which is needed for toggling to work)
margin_note_custom <- function (text, icon = "⊕", number_column) {
marginnote_html_custom <- function (text = "", icon = "⊕")
{
sprintf(paste0("<label for=\"tufte-mn-", {{number_column}},
"\" class=\"margin-toggle\">%s</label>",
"<input type=\"checkbox\" id=\"tufte-mn-", {{number_column}},
"\" class=\"margin-toggle\">%s"),
icon, text)
}
if (is_html_output()) {
marginnote_html_custom(sprintf("<span class=\"marginnote\">%s</span>",
text), icon)
} else {
warning("margin_note_custom() only works for HTML output",
call. = FALSE)
text
}
}
## data ----------------
df_translations <- read_csv("materials/FREN 8510 McGrady Silence Translations - Sheet1.csv",
col_types = cols(.default = "c",
Line = col_integer())) %>%
#convert NAs to empty strings
mutate(across(.cols = c(Line, `My Translation`, Notes, `Sound Priority Translation Notes`),
~ifelse(is.na(.), " ", .))) %>%
#fill in Word Order Priority Translation with My Translation
mutate(`Word Order Priority Translation` = case_when(
is.na(`Word Order Priority Translation`) ~ `My Translation`,
TRUE ~ `Word Order Priority Translation`
)) %>%
#create line number column with number every 5 lines
rename(Line_all = Line) %>%
mutate(Line = case_when((Line_all + 1 )%% 5 == 0 ~ as.character(Line_all),
TRUE ~ " ")) %>%
mutate(
#convert notes to margin notes (only when there is something in the Notes column, otherwise leave blank)
Notes_html = case_when(
Notes != " " ~ margin_note_custom(paste0(
#paste the manicule to the margin note
'<img src="materials/manicule.png" style="height: 1.3em; vertical-align: bottom; display: inline-block; margin-left: -10%" /> ',
Notes),
# icon = "☜"
#make the icon to expand the margin note when the window is narrow also a manicule
icon = '<img src="materials/manicule.png" style="height: 1.3em; vertical-align: bottom; display: inline-block; " />',
number_column = Line_all
),
TRUE ~ ""
),
#convert notes to margin notes (only when there is something in the Notes column, otherwise leave blank)
`Sound Priority Translation Notes html` = case_when(
`Sound Priority Translation Notes` != " " ~ margin_note_custom(paste0(
#paste the manicule to the margin note
'<img src="materials/manicule.png" style="height: 1.3em; vertical-align: bottom; display: inline-block; margin-left: -10%" /> ',
`Sound Priority Translation Notes`),
# icon = "☜"
#make the icon to expand the margin note when the window is narrow also a manicule
icon = '<img src="materials/manicule.png" style="height: 1.3em; vertical-align: bottom; display: inline-block; " />',
number_column = Line_all
),
TRUE ~ ""
),
#paste the margin notes to the last column
`My Translation w/ notes` = paste(`My Translation`, Notes_html),
`Word Order Priority Translation w/ notes` = paste(`Word Order Priority Translation`, Notes_html),
`Sound Priority Translation w/ notes` = paste(`Sound Priority Translation`, `Sound Priority Translation Notes html`)
)
df_translations_old <- df_translations %>%
select(Line, `Psaki (1991) Translation`, `Roche-Mahdi (2007) Translation`)