Hi,
I think you can search in the parent environments by "brutal force"
like this (I don't guarantee it works for all Sweave documents):
if ((n.parents <- length(sys.parents())) >= 3) {
for (i in seq_len(n.parents) - 1) {
if ('chunkopts' %in% ls(envir = sys.frame(i))) {
chunkopts = get('chunkopts', envir = sys.frame(i))
if (all(c('prefix.string', 'label') %in%
names(chunkopts))) {
## yes, I'm in Sweave w.p. 95% :)
chunkopts$label # this is what you want
break
}
}
}
}
Regards,
Yihui
--
Yihui Xie <xieyihui at gmail.com>
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA
On Sat, Apr 16, 2011 at 5:12 AM, David.Epstein
<David.Epstein at warwick.ac.uk> wrote:> I would like to print the label of each code chunk, just before printing
the
> code chunk itself. Is that possible using SweaveHooks, or by some other
> mechanism?
>
> Thanks
> David
>
> --
> View this message in context:
http://r.789695.n4.nabble.com/Sweave-SweaveHooks-and-printing-the-label-tp3453829p3453829.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>