Skip to content

Use roxygen2-like style for simple links#73

Merged
MichaelChirico merged 1 commit intomasterfrom
roxy-links
Oct 14, 2024
Merged

Use roxygen2-like style for simple links#73
MichaelChirico merged 1 commit intomasterfrom
roxy-links

Conversation

@MichaelChirico
Copy link
Copy Markdown
Collaborator

Another hack at the edifice of #61: trying to migrate to roxygen2-style links first.

This PR only look for cases using style \code{\link{FUN}} on master that are winding up as \code{\link[=FUN]{FUN()}} in {roxygen2} style.

Repro code:

# Find objects linked like `\link[=FUN]{FUN()}` on roxygen branch
rd = Sys.glob("man/*.Rd")
simple_call_links = sort(unique(unlist(lapply(rd, function(f) {
  l = readLines(f)
  re = R"([\\]link\[=(.*)\]\{\1\(\)\})"
  l = grep(re, l, value=TRUE, perl=TRUE)
  idx = gregexpr(re, l, perl=TRUE)
  mapply(
    \(line, start, len) substr(line, start, start+len-1),
    l, lapply(idx, attr, "capture.start"), lapply(idx, attr, "capture.length"),
    USE.NAMES=FALSE
  )
}))))

simple_call_links = setdiff(simple_call_links, "integer64") # ambiguity of the data type vs. the function

# change to patch branch
system('git checkout roxy-links')

re = sprintf(R"([\]code\{[\]link\{(%s)\}\})", paste(gsub(".", "[.]", simple_call_links, fixed = TRUE), collapse="|"))
for (f in rd) {
  l = readLines(f)
  l = gsub(re, R"(\code{\link[=\1]{\1()}})", l)
  writeLines(l, f)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant