@@ -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+
365383processRdIfdefs <- 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" )
0 commit comments