-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathposts.Rmd
More file actions
75 lines (65 loc) · 2.09 KB
/
posts.Rmd
File metadata and controls
75 lines (65 loc) · 2.09 KB
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
# CREATE POSTS
```{r read, echo = FALSE, results = FALSE, warning = FALSE, message = FALSE}
# read TeX file
tex_data <- TeXCheckR::read_tex_document(
file.path("./docs", "Ciencia-com-R.tex")
)
# source scripts
source(file.path("R", "tex_to_df.R"), local = knitr::knit_global())
df <- parse_tex_structure(tex_data)
# CLEAN df
df <- df |>
dplyr::filter(
!is.na(graphic) |
(
!is.na(references) &
!grepl("REF", item) &
references != "REF" &
item != ".\\textsuperscript{\\citeproc{ref-REF}{\\textbf{REF?}}}"
)
)
# BUILD CHAPTER INDEX (order = first appearance in df)
chapter_index <- df |>
dplyr::distinct(chapter) |>
dplyr::mutate(chapter_id = dplyr::row_number())
# BUILD SECTION INDEX (restart at 1 per chapter)
section_index <- df |>
dplyr::distinct(chapter, section) |>
dplyr::group_by(chapter) |>
dplyr::mutate(section_id = dplyr::row_number()) |>
dplyr::ungroup()
# BUILD SUBSECTION INDEX (restart at 1 per chapter + section)
subsection_index <- df |>
dplyr::distinct(chapter, section, subsection) |>
dplyr::group_by(chapter, section) |>
dplyr::mutate(subsection_id = dplyr::row_number()) |>
dplyr::ungroup()
# JOIN INDICES BACK INTO df
df <- df |>
dplyr::left_join(chapter_index, by = "chapter") |>
dplyr::left_join(section_index, by = c("chapter", "section"))
# JOIN SUBSECTION INDEX BACK INTO df
df <- df |>
dplyr::left_join(
subsection_index,
by = c("chapter", "section", "subsection")
)
```
```{r save, echo = FALSE, results = FALSE, warning = FALSE, message = FALSE}
# delete .PNG files from posts folder
delete_files <- list.dirs("posts", full.names = TRUE)
unlink(delete_files, recursive = TRUE)
# create folder "posts"
dir.create("posts", showWarnings = FALSE)
# read bib file
bib <- RefManageR::ReadBib(file.path("./bib", "references.bib"))
# save all posts
source(file.path("R", "savePost.R"), local = knitr::knit_global())
for (i in 1:nrow(df)) {
# progress bar
cat(paste0(round(i / nrow(df) * 100), '% completed'))
SavePost_df(entry = df[i, ], bib = bib)
if (i == nrow(df)) cat(': Done')
else cat('\014')
}
```