From 75699d43eb476299707d1fa7fc77f66c255b434d Mon Sep 17 00:00:00 2001 From: hornik Date: Thu, 10 Aug 2023 03:20:57 +0000 Subject: [PATCH] Record Rd generator. git-svn-id: https://svn.r-project.org/R/trunk@84925 00db46b3-68df-0310-9c12-caf00c1e9a41 --- src/library/tools/R/RdConv2.R | 7 ++++++- src/library/tools/R/htmltools.R | 19 ++++++------------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/library/tools/R/RdConv2.R b/src/library/tools/R/RdConv2.R index a5c4a0b9cea..52bb9ada7e2 100644 --- a/src/library/tools/R/RdConv2.R +++ b/src/library/tools/R/RdConv2.R @@ -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") @@ -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) diff --git a/src/library/tools/R/htmltools.R b/src/library/tools/R/htmltools.R index cf607e48cd5..2d3ed4d2156 100644 --- a/src/library/tools/R/htmltools.R +++ b/src/library/tools/R/htmltools.R @@ -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]