Search code examples
rknitrknitr-spin

Can knitr::spin() pick up global options?


knitr::spin() is a great tool for those that prefer to write code first and text second. I would like to use it to produce documents with little code echoing, but lots of output and text comments. However, every time that I turn off echoing and then add some text, spin() turns echoing back on again.

Is there anyway for spin() to pick up global options from the r script that it is spinning? e.g.one conceptual way could be putting

#+ opts_chunk$set(echo=FALSE)

as the first line but it doesn't seem to be recognised by spin(). Is there any way to achieve this?

Mark


Solution

  • Yes, there is a way: as when knit'ing, just set global options in an initial setup chunk.

    So, for example, the following spins up just fine, resulting in output that does not echo any of the supplied code.

    #+ setup, include=FALSE
    opts_chunk$set(echo=FALSE)
    
    #+ aChunk
    plot(rnorm(99))
    
    #+ anotherChunk
    1:100