Skip to content

Commit 126423e

Browse files
author
hornik
committed
Have .package_code_using_R_4.x_syntax() also look at code in Rd examples.
Based on R-devel post by Ivan Krylov. git-svn-id: https://svn.r-project.org/R/trunk@87814 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 3bee0a1 commit 126423e

File tree

1 file changed

+44
-6
lines changed

1 file changed

+44
-6
lines changed

src/library/tools/R/utils.R

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ function(dir, predicate = NULL, recursive = FALSE, .worker = NULL,
851851

852852
which <- match.arg(which,
853853
c("code", "vignettes", "tests",
854-
"NAMESPACE", "CITATION"),
854+
"NAMESPACE", "CITATION", "docs"),
855855
several.ok = TRUE)
856856
code_files <-
857857
c(character(),
@@ -881,6 +881,22 @@ function(dir, predicate = NULL, recursive = FALSE, .worker = NULL,
881881
names(calls) <-
882882
.file_path_relative_to_dir(code_files, dirname(dir))
883883

884+
if("docs" %in% which) {
885+
db <- Rd_db(dir = dir)
886+
names(db) <- file.path(basename(dir), "man", names(db))
887+
calls <-
888+
c(calls,
889+
Filter(length,
890+
lapply(db,
891+
function(e) {
892+
f <- tempfile()
893+
on.exit(unlink(f))
894+
Rd2ex(e, f)
895+
if(file.exists(f))
896+
.worker(f, "UTF-8")
897+
})))
898+
}
899+
884900
calls
885901
}
886902

@@ -2107,8 +2123,7 @@ function(packages = NULL, FUN, ..., pattern = NULL, verbose = TRUE,
21072123
function(dir)
21082124
{
21092125
dir <- file_path_as_absolute(dir)
2110-
wrk <- function(f) {
2111-
p <- file.path(dir, "R", f)
2126+
wrk <- function(p, f) {
21122127
x <- utils::getParseData(parse(p, keep.source = TRUE))
21132128
i1 <- which(x$token %in% c("PIPE", "'\\\\'"))
21142129
i2 <- which(x$token == "PLACEHOLDER")
@@ -2137,13 +2152,36 @@ function(dir)
21372152
} else
21382153
NULL
21392154
}
2140-
one <- function(f)
2141-
tryCatch(wrk(f), error = function(e) NULL)
21422155

21432156
files <- list_files_with_type(file.path(dir, "R"), "code",
21442157
full.names = FALSE,
21452158
OS_subdirs = c("unix", "windows"))
2146-
do.call(rbind, lapply(files, one))
2159+
db <- Rd_db(dir = dir)
2160+
2161+
do.call(rbind,
2162+
c(Map(function(u, v) {
2163+
tryCatch({
2164+
wrk(u, v)
2165+
}, error = function(e) NULL)
2166+
},
2167+
file.path(dir, "R", files),
2168+
files,
2169+
USE.NAMES = FALSE),
2170+
Map(function(u, v) {
2171+
tryCatch({
2172+
p <- tempfile()
2173+
on.exit(unlink(p))
2174+
## Need to extract the code in the examples.
2175+
## Rd2ex() does that and more, but provides no
2176+
## output if there are no examples ...
2177+
Rd2ex(u, p)
2178+
if(file.exists(p))
2179+
wrk(p, v)
2180+
}, error = function(e) NULL)
2181+
},
2182+
db,
2183+
names(db),
2184+
USE.NAMES = FALSE)))
21472185
}
21482186

21492187
## ** .package_depends_on_R_at_least

0 commit comments

Comments
 (0)