Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use roxygen2-like style for simple links #73

Merged
merged 1 commit into from
Oct 14, 2024
Merged

Conversation

MichaelChirico
Copy link
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)
}

@MichaelChirico MichaelChirico merged commit a24a78e into master Oct 14, 2024
8 checks passed
@MichaelChirico MichaelChirico deleted the roxy-links branch October 14, 2024 05:01
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