Re: [R] Sweave, SweaveHooks and printing the label

From: Yihui Xie <xie_at_yihui.name>
Date: Sat, 16 Apr 2011 12:50:53 -0500

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.
> ______________________________________________ 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.
Received on Sat 16 Apr 2011 - 17:55:20 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 16 Apr 2011 - 19:10:31 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive