Skip to content

Commit cb76a84

Browse files
author
hornik
committed
Make Rdfile info conveniently available for Sexpr code.
git-svn-id: https://svn.r-project.org/R/trunk@88497 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 98f30d1 commit cb76a84

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

src/library/tools/R/RdConv2.R

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,14 @@ processRdChunk <- function(code, stage, options, env, macros)
206206
if (is.null(opts <- attr(code, "Rd_option"))) opts <- ""
207207
codesrcref <- attr(code, "srcref")
208208
Rdfile <- attr(codesrcref, "srcfile")$filename
209+
## Provide Rdfile for easy access to Sexpr code (instead of having
210+
## to look in the call stack for the call to processRdChunk() and
211+
## get Rdfile from the correspnding frame.
212+
## We may want to provide Rdfile and other information for the whole
213+
## prepare_Rd() processing, but that recalls itself so dropping the
214+
## information on exit is not straightforward.
215+
processRdChunk_data_store(list(Rdfile = Rdfile))
216+
on.exit(processRdChunk_data_store(NULL))
209217
options <- utils:::SweaveParseOptions(opts, options, RweaveRdOptions)
210218
if (stage == options$stage) {
211219
# The code below is very similar to RWeaveLatexRuncode, but simplified
@@ -362,6 +370,16 @@ processRdChunk <- function(code, stage, options, env, macros)
362370
replaceRdSrcrefs(res, codesrcref)
363371
}
364372

373+
processRdChunk_data_store <- local({
374+
.store <- NULL
375+
function(new) {
376+
if(!missing(new))
377+
.store <<- new
378+
else
379+
.store
380+
}
381+
})
382+
365383
processRdIfdefs <- function(blocks, defines)
366384
{
367385
recurse <- function(block) {
@@ -470,6 +488,10 @@ prepare_Rd <-
470488
srcref <- attr(Rd, "srcref")
471489
if (is.null(Rdfile) && !is.null(srcref))
472490
Rdfile <- attr(srcref, "srcfile")$filename
491+
## prepare_Rd_data_store(list(Rdfile = Rdfile))
492+
## prepare_Rd_data_store(Rdfile)
493+
## saveRDS(prepare_Rd_data_store(), file = "~/tmp/yyy2.rds")
494+
## on.exit(prepare_Rd_data_store(NULL))
473495
if (fragment) meta <- NULL
474496
else {
475497
pratt <- attr(Rd, "prepared")

src/library/tools/R/RdHelpers.R

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,11 @@ function(x)
210210
use.names = FALSE)
211211
if(any(ind <- nzchar(footers)))
212212
footers[ind] <- paste("\\cr", footers[ind])
213-
paste(sprintf("%s\\if{html}{\u2060\\out{<span id=\"reference+%s\">}}%s\\if{html}{\\out{</span>}}%s",
213+
rdfile <- processRdChunk_data_store()$Rdfile
214+
rdpath <- if(length(rdfile)) basename(rdfile) else ""
215+
paste(sprintf("%s\\if{html}{\u2060\\out{<span id=\"reference+%s+%s\">}}%s\\if{html}{\\out{</span>}}%s",
214216
headers,
217+
rdpath,
215218
string2id(.bibentry_get_key(y)),
216219
toRd(y),
217220
footers),
@@ -258,6 +261,8 @@ function(x, textual = FALSE)
258261
return("")
259262
y <- character(n)
260263
prev <- Rd_expr_bibcite_keys_cited()
264+
rdfile <- processRdChunk_data_store()$Rdfile
265+
rdpath <- if(length(rdfile)) basename(rdfile) else ""
261266
if(textual) {
262267
for(i in seq_len(n)) {
263268
key <- keys[i]
@@ -268,7 +273,8 @@ function(x, textual = FALSE)
268273
if(any(ind <- nzchar(before)))
269274
before[ind] <- paste0(before[ind], " ")
270275
y <- paste0(before,
271-
sprintf("\\if{html}{\\out{<a href=\"#reference+%s\">}}",
276+
sprintf("\\if{html}{\\out{<a href=\"#reference+%s+%s\">}}",
277+
rdpath,
272278
string2id(keys)),
273279
y,
274280
rep_len("\\if{html}{\\out{</a>}}", n),
@@ -288,7 +294,8 @@ function(x, textual = FALSE)
288294
after[ind] <- paste0(", ", after[ind])
289295
y <- paste0("(",
290296
paste0(before,
291-
sprintf("\\if{html}{\\out{<a href=\"#reference+%s\">}}",
297+
sprintf("\\if{html}{\\out{<a href=\"#reference+%s+%s\">}}",
298+
rdpath,
292299
string2id(keys)),
293300
y,
294301
rep_len("\\if{html}{\\out{</a>}}", n),

0 commit comments

Comments
 (0)