Skip to content

Commit

Permalink
Record Rd generator.
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.r-project.org/R/trunk@84925 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
hornik committed Aug 10, 2023
1 parent c9934dd commit 75699d4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
7 changes: 6 additions & 1 deletion src/library/tools/R/RdConv2.R
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,11 @@ prepare2_Rd <- function(Rd, Rdfile, stages)
}
}

generator <- if((sections[1L] == "COMMENT") &&
startsWith(Rd[[1L]], "% Generated by"))
c(Rd[[1L]])
else ""

## Drop all the parts that are not rendered
extras <- c("COMMENT", "TEXT", "\\docType", "\\Rdversion", "\\RdOpts",
"USERMACRO", "\\newcommand", "\\renewcommand")
Expand Down Expand Up @@ -576,7 +581,7 @@ prepare2_Rd <- function(Rd, Rdfile, stages)
if(grepl("[!|@]", name_text))
warnRd(Rd[[2L]], Rdfile, "\\name should not contain !, | or @")
## is this really what we want? docTypes is a vector.
structure(Rd, meta = list(docType = docTypes))
structure(Rd, meta = list(docType = docTypes, generator = generator))
}

## auxiliary, currently called only from prepare_Rd(*, stage3 = TRUE)
Expand Down
19 changes: 6 additions & 13 deletions src/library/tools/R/htmltools.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,12 @@ tidy_validate_package_Rd_files_from_dir <- function(dir, auto = NA, verbose) {
message(sprintf("* Package: %s", basename(d)))
db <- tools::Rd_db(dir = d)
if(!is.na(auto)) {
## Rd files auto-generated by roxygen2 start with
## % Generated by roxygen2
## However, in the Rd db we don't have this info, as we go
## via stage 2 Rd preparation which drops COMMENT elements
## (we might want to make this more customizable?). So we
## try to get the info from the Rd file sources.
is <- vapply(file.path(d, "man", names(db)),
function(f) {
if(!file.exists(f))
FALSE
else
(readChar(f, 23, useBytes = TRUE) ==
"% Generated by roxygen2")
is <- vapply(db,
function(e) {
g <- attr(e, "meta")$generator
(is.character(g) &&
(length(g) == 1L) &&
startsWith(g, "% Generated by roxygen2"))
},
NA)
db <- db[if(auto) is else !is]
Expand Down

0 comments on commit 75699d4

Please sign in to comment.