8

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

Peter
  • 7,460
  • 2
  • 47
  • 68
Mark Payne
  • 557
  • 5
  • 12

2 Answers2

7

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
Josh O'Brien
  • 159,210
  • 26
  • 366
  • 455
0

How would it work to set global options such as path to figures directory from the command line?

I have something like: Rscript -e "require(knitr)" -e "knitr::spin('script.R')" -e 'knitr::opts_chunk$set(fig.path="./figs")', but it always stores pictures in a newly created folder called figures.

Peter Pfand
  • 155
  • 1
  • 1
  • 7