Skip to content

Commit

Permalink
Have .package_code_using_R_4.x_syntax() also look at code in Rd examp…
Browse files Browse the repository at this point in the history
…les.

Based on R-devel post by Ivan Krylov.

git-svn-id: https://svn.r-project.org/R/trunk@87814 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
hornik committed Feb 24, 2025
1 parent 3bee0a1 commit 126423e
Showing 1 changed file with 44 additions and 6 deletions.
50 changes: 44 additions & 6 deletions src/library/tools/R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ function(dir, predicate = NULL, recursive = FALSE, .worker = NULL,

which <- match.arg(which,
c("code", "vignettes", "tests",
"NAMESPACE", "CITATION"),
"NAMESPACE", "CITATION", "docs"),
several.ok = TRUE)
code_files <-
c(character(),
Expand Down Expand Up @@ -881,6 +881,22 @@ function(dir, predicate = NULL, recursive = FALSE, .worker = NULL,
names(calls) <-
.file_path_relative_to_dir(code_files, dirname(dir))

if("docs" %in% which) {
db <- Rd_db(dir = dir)
names(db) <- file.path(basename(dir), "man", names(db))
calls <-
c(calls,
Filter(length,
lapply(db,
function(e) {
f <- tempfile()
on.exit(unlink(f))
Rd2ex(e, f)
if(file.exists(f))
.worker(f, "UTF-8")
})))
}

calls
}

Expand Down Expand Up @@ -2107,8 +2123,7 @@ function(packages = NULL, FUN, ..., pattern = NULL, verbose = TRUE,
function(dir)
{
dir <- file_path_as_absolute(dir)
wrk <- function(f) {
p <- file.path(dir, "R", f)
wrk <- function(p, f) {
x <- utils::getParseData(parse(p, keep.source = TRUE))
i1 <- which(x$token %in% c("PIPE", "'\\\\'"))
i2 <- which(x$token == "PLACEHOLDER")
Expand Down Expand Up @@ -2137,13 +2152,36 @@ function(dir)
} else
NULL
}
one <- function(f)
tryCatch(wrk(f), error = function(e) NULL)

files <- list_files_with_type(file.path(dir, "R"), "code",
full.names = FALSE,
OS_subdirs = c("unix", "windows"))
do.call(rbind, lapply(files, one))
db <- Rd_db(dir = dir)

do.call(rbind,
c(Map(function(u, v) {
tryCatch({
wrk(u, v)
}, error = function(e) NULL)
},
file.path(dir, "R", files),
files,
USE.NAMES = FALSE),
Map(function(u, v) {
tryCatch({
p <- tempfile()
on.exit(unlink(p))
## Need to extract the code in the examples.
## Rd2ex() does that and more, but provides no
## output if there are no examples ...
Rd2ex(u, p)
if(file.exists(p))
wrk(p, v)
}, error = function(e) NULL)
},
db,
names(db),
USE.NAMES = FALSE)))
}

## ** .package_depends_on_R_at_least
Expand Down

0 comments on commit 126423e

Please sign in to comment.