Is there a way to refer to but not expand another chunk in knitr output?

59 views Asked by At

I would like to be able to use knitr's facility for referring to other code chunks by their label, but sometimes prohibit expansion in the ultimate typesetting, leaving only a reference to the chunk label. This is mainly useful when I am explaining an overview of some procedure, and want to mention but elide the details of bookkeeping code, deferring those details to elsewhere in the narrative.

During the actual code execution or purling process, I want them to be expanded as usual. But typesetting might look like:

my_function <- function(a, b) {
  <check-arguments-and-raise-errors>
  <pre-process-the-arguments>

  ## Here we do the real work
  a2 <- a^2
  ab <- a*b
  b2 <- b^2
  main_result <- a2 - 2*ab + b2

  <package-up-the-result>

  return(packaged_result)
}

I can't tell whether this is impossible or I'm just missing it in the documentation. I think it's the default behavior in noweb, but impossible in Sweave, so I'm not sure what to expect.

0

There are 0 answers