11# File src/library/tools/R/bibtools.R
22# Part of the R package, https://www.R-project.org
33#
4- # Copyright (C) 2025 The R Core Team
4+ # Copyright (C) 2025-2026 The R Core Team
55#
66# This program is free software; you can redistribute it and/or modify
77# it under the terms of the GNU General Public License as published by
@@ -174,14 +174,16 @@ function(bib)
174174function (dir )
175175{
176176 dir <- file_path_as_absolute(dir )
177-
177+
178178 # # Base packages are special as they have no partial Rd db, and
179- # # Rd_db() re-orders sections after processing Sexprs, so we need to
179+ # # Rd_db() re-orders sections after processing Sexprs, so we need to
180180 # # go via .build_Rd_db() which allows step control.
181181 # # For non-base packages, we really need build/partial.rdb (which we
182182 # # only have for the package sources) to check that all bibentry
183183 # # macros were properly expanded.
184- db <- .build_Rd_db(dir , step = 1L )
184+ # # There is no need to process \Sexpr code here (and we are not
185+ # # prepared to find the installed package/REFERENCES anyway).
186+ db <- .build_Rd_db(dir , step = 1L , stages = NULL )
185187 if (length(db )) {
186188 first <- nchar(file.path(dir , " man" )) + 2L
187189 names(db ) <- substring(names(db ), first )
@@ -190,33 +192,34 @@ function(dir)
190192 x <- Filter(length , lapply(db , .bibentries_cited_or_shown ))
191193 if (! length(x ))
192194 return (NULL )
193-
195+
194196 u <- FALSE
195-
197+
196198 if (basename(dir ) %notin % .get_standard_package_names()$ base ) {
197199 # # Check whether we got everything from the build stage
198200 # # expansions.
199- f <- file.path(dir , " build" , " partial.rdb" )
200- if (! file.exists(f )) {
201+ built_file <- file.path(dir , " build" , " partial.rdb" )
202+ if (! file.exists(built_file )) {
201203 u <- TRUE
202204 } else {
203- y <- lapply(readRDS(f )[names(x )], .bibentries_cited_or_shown )
205+ y <- lapply(readRDS(built_file )[names(x )],
206+ .bibentries_cited_or_shown )
204207 # # Cannot simply use identical() as entries in the partial
205208 # # Rd db are subject to section re-ordering.
206209 # # <FIXME>
207210 # # Is this still true now that we go via .build_Rd_db()?
208211 # # </FIXME>
209212 g <- function (u , v ) {
210213 is.null(v ) || # built with \bib stubs/unknowns in R < 4.6.0
211- length(setdiff(split(u , row(u )), split(v , row(v ))) > 0L )
214+ length(setdiff(split(u , row(u )), split(v , row(v )))) > 0L
212215 }
213216 if (any(unlist(Map(g , x , y ), use.names = FALSE )))
214217 u <- TRUE
215218 else
216219 x <- y
217220 }
218221 }
219-
222+
220223 f <- function (x ) {
221224 if (! length(x ))
222225 return (NULL )
0 commit comments