This repository has been archived by the owner on Apr 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
altdoc_postprocessing.R
83 lines (72 loc) · 2.21 KB
/
altdoc_postprocessing.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
### To be run after altdoc::render_docs()
list_man_html = list.files("docs/man",
pattern = "\\.html$", full.names = TRUE,
recursive = TRUE
)
### Make the "Usage" section prettier (if there is one):
### DataFrame_describe(...) -> <DataFrame>$describe()
classes = c(
"Series", "DataFrame", "LazyFrame", "GroupBy",
"LazyGroupBy", "IO", "RThreadHandle", "SQLContext", "S3",
"Expr", "pl"
)
to_modify = grep(
paste0("/", paste(classes, collapse = "|")),
list_man_html,
value = TRUE
)
for (i in to_modify) {
which_class = gsub("docs/man/([^_]+).*$", "\\1", i, perl = TRUE)
orig = readLines(i, warn = FALSE)
if (!any(grepl("<h2 id=\"usage\">Usage</h2>", orig))) {
next
}
# IO functions are DataFrame or LazyFrame methods
if (which_class == "IO") {
if (any(grepl("<code class='language-R'>LazyFrame_sink", orig))) {
which_class <<- "LazyFrame"
} else if (any(grepl("<code class='language-R'>DataFrame_write", orig))) {
which_class <<- "DataFrame"
}
}
# prefix with pl$ for read/scan
if (which_class == "IO") {
which_input = if (any(grepl("<code class='language-R'>read_", orig))) {
"read"
} else if (any(grepl("<code class='language-R'>scan_", orig))) {
"scan"
} else {
""
}
new = gsub(
paste0("<code class='language-R'>", which_input, "_"),
paste0("<code class='language-R'>pl$", which_input, "_"),
orig
)
} else if (which_class == "pl") {
new = gsub(
"<code class='language-R'>pl_",
"<code class='language-R'>pl$",
orig
)
} else if (which_class %in% c(
"ExprArr", "ExprBin", "ExprCat", "ExprDT", "ExprList",
"ExprMeta", "ExprName", "ExprStr", "ExprStruct"
)) {
subns = tolower(gsub("Expr", "", which_class))
new = gsub(
paste0("<code class='language-R'>", which_class, "_"),
paste0("<code class='language-R'><Expr>$", subns, "$"),
orig
)
} else {
new = gsub(
paste0("<code class='language-R'>", which_class, "_"),
paste0("<code class='language-R'><", which_class, ">$"),
orig
)
}
# fix escaping of left-angle brackets (not needed for right-angle brackets)
new = gsub("\\\\<", "<", new)
writeLines(new, i)
}