Skip to content

Commit

Permalink
Improving function reference index rendering: removing aliases and sh…
Browse files Browse the repository at this point in the history
…orthands for cleaner presentation.
  • Loading branch information
SebKrantz committed Oct 13, 2023
1 parent 738482e commit 46910a1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
9 changes: 8 additions & 1 deletion R/build-reference-index.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
data_reference_index <- function(pkg = ".") {
pkg <- as_pkgdown(pkg)

# This removes shorthands from reference index
sh <- getNamespace("collapse")[[".SHORTHANDS"]]
sh <- sh[!endsWith(sh, "<-")]
sh <- c(sh, paste0("`", sh), ".quantile", ".range", "`[", "`$")
pkg$topics$funs <- lapply(pkg$topics$funs, function(y) if(length(y))
y[rowSums(do.call(cbind, lapply(sh, startsWith, x = y))) <= 0] else y)

meta <- pkg$meta[["reference"]] %||% default_reference_index(pkg)
if (length(meta) == 0) {
return(list())
Expand All @@ -17,7 +24,7 @@ data_reference_index <- function(pkg = ".") {
rows <- Filter(function(x) !x$is_internal, rows)

print_yaml(list(
pagetitle = tr_("Function reference"),
pagetitle = tr_("Function Reference"),
rows = rows,
has_icons = has_icons
))
Expand Down
10 changes: 10 additions & 0 deletions R/rd.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ parse_Rd2 <- function(file, ...) {
lines <- gsub("\\tab\\tab", "\\tab", gsub("\\tab \\tab", "\\tab", lines, fixed = TRUE), fixed = TRUE)
lines <- gsub("\\tabular{lll}", "\\tabular{ll}", lines, fixed = TRUE)
}
clpns <- getNamespace("collapse")
nam <- names(clpns)
rm_alias <- c(clpns[[".SHORTHANDS"]],
setdiff(nam[startsWith(nam, ".")], c(".", ".c")),
nam[startsWith(nam, "[")],
nam[startsWith(nam, "$")])
rm_alias <- paste0("\\alias{", rm_alias)
lines <- lines[!startsWith(lines, "%")]
lines <- lines[!startsWith(lines, "\\alias{A")]
lines <- lines[rowSums(sapply(rm_alias, startsWith, x = lines, USE.NAMES = FALSE)) <= 0]
tmp <- tempfile(fileext = ".Rd")
write_lines(substcr(substcr(substcr(substcr(substcr(lines))))), tmp)
res <- tools::parse_Rd(tmp, ...)
Expand Down

0 comments on commit 46910a1

Please sign in to comment.