Skip to content

Commit e7cf9bd

Browse files
author
hornik
committed
Improvements for concordances. By Duncan Murdoch.
git-svn-id: https://svn.r-project.org/R/trunk@88957 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 75ea8d1 commit e7cf9bd

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

src/library/tools/R/Rconcordance.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,9 @@ stringToConcordance <- function(s) {
256256
addConcordance <- function(conc, s) {
257257
prev <- stringToConcordance(s)
258258
if (!is.null(prev)) {
259-
conc$srcFile <- rep_len(conc$srcFile, length(conc$srcLine))
259+
conc$srcFile <- c(rep_len(NA_character_, conc$offset),
260+
rep_len(conc$srcFile, length(conc$srcLine)))
261+
conc$offset <- 0L
260262
i <- seq_along(prev$srcLine)
261263
conc$srcFile[prev$offset + i] <- prev$srcFile
262264
conc$srcLine[prev$offset + i] <- prev$srcLine

src/library/tools/R/pkg2HTML.R

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@
9494
Links = Links, Links2 = Links2,
9595
...)
9696
)
97-
list(outlines = outlines, info = attr(h, "info"))
97+
list(outlines = outlines, info = attr(h, "info"),
98+
concordance = attr(h, "concordance"))
9899
}
99100
structure(lapply(db, rd2lines, standalone = FALSE, ...),
100101
pkgdir = pkgdir, src.type = src.type,
@@ -115,13 +116,14 @@ pkg2HTML <- function(package, dir = NULL, lib.loc = NULL,
115116
...,
116117
Rhtml = FALSE,
117118
mathjax_config = file.path(R.home("doc"), "html", "mathjax-config.js"),
118-
include_description = TRUE)
119+
include_description = TRUE,
120+
concordance = FALSE)
119121
{
120122
toc_entry <- match.arg(toc_entry)
121123
hcontent <- .convert_package_rdfiles(package = package, dir = dir, lib.loc = lib.loc,
122124
outputEncoding = outputEncoding,
123125
Rhtml = Rhtml, hooks = hooks,
124-
texmath = "katex", prism = prism, ...)
126+
texmath = "katex", prism = prism, concordance = concordance, ...)
125127
descfile <- attr(hcontent, "descfile")
126128
src.type <- attr(hcontent, "src.type")
127129
pkgdir <- attr(hcontent, "pkgdir")
@@ -177,8 +179,19 @@ pkg2HTML <- function(package, dir = NULL, lib.loc = NULL,
177179
MATHJAX_CONFIG_STATIC = mathjax_config,
178180
language = language)
179181

180-
writeHTML <- function(..., sep = "\n", append = TRUE)
182+
linecount <- 0L
183+
writeHTML <- function(..., sep = "\n", append = TRUE) {
181184
cat(..., file = out, sep = sep, append = append)
185+
if (concordance) {
186+
if (!append)
187+
linecount <<- 0L
188+
if (sep == "\n")
189+
linecount <<- linecount + sum(lengths(list(...)))
190+
# Also add any embedded newlines...
191+
linecount <<- linecount + sum(sapply(list(...),
192+
function(s) sum(unlist(gregexpr("\n", s, fixed = TRUE)) > 0)))
193+
}
194+
}
182195

183196
## cat(hfcomps$header, fill = TRUE) # debug
184197
writeHTML(hfcomps$header, sep = "", append = FALSE)
@@ -200,7 +213,17 @@ pkg2HTML <- function(package, dir = NULL, lib.loc = NULL,
200213
'<main>')
201214

202215
if (include_description) writeHTML(.DESCRIPTION_to_HTML(descfile))
203-
lapply(hcontent, function(h) writeHTML("<hr>", h$outlines))
216+
lapply(hcontent, function(h) {
217+
if (concordance) {
218+
conc <- h$concordance
219+
if (inherits(conc, "Rconcordance")) {
220+
conc$offset <- conc$offset + linecount + 1L
221+
h$outlines[length(h$outlines)] <-
222+
paste("<!--", as.character(conc), "-->")
223+
}
224+
}
225+
writeHTML("<hr>", h$outlines)
226+
})
204227
writeHTML('</main>')
205228
writeHTML(hfcomps$footer, sep = "")
206229
invisible(out)

src/library/tools/man/pkg2HTML.Rd

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ pkg2HTML(package, dir = NULL, lib.loc = NULL,
2222
...,
2323
Rhtml = FALSE,
2424
mathjax_config = file.path(R.home("doc"), "html", "mathjax-config.js"),
25-
include_description = TRUE)
25+
include_description = TRUE,
26+
concordance = FALSE)
2627
}
2728
\arguments{
2829
\item{package}{ typically a character string giving the name of an
@@ -75,6 +76,8 @@ pkg2HTML(package, dir = NULL, lib.loc = NULL,
7576
\item{include_description}{ logical flag indicating whether the output
7677
should begin with the contents of the \code{DESCRIPTION} file.
7778
}
79+
\item{concordance}{ logical flag indicating whether the output
80+
should contain concordance information.}
7881
}
7982

8083
\details{

0 commit comments

Comments
 (0)