Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 963
Mark Payne Avatar asked Feb 11 '14 21:02

Mark Payne


People also ask

What do the {knitr} options do?

Having a consistent set of {knitr} options makes standardising figures across documents (slightly) easier. These options control the graphics options. : create a standard directory where generated figures are stored. For our Hugo blog posts, we set

What is the difference between knitr spin and knitr knit?

In short: knitr::spin is similar to knitr::knit in that it takes as input a file with R code + formatting + text and produces a nice readable report, such as an HTML or markdown document. The difference lies in the input: spin operates on R scripts ( .R ), while knit requires a literate programming file ( .Rmd, .Rnw, etc.).

Should I use spin or knit for my R reports?

I think if the output is very text-heavy and focuses a lot more on formatting and visual, and only includes some bits of R code here and there, then knit would be more appropriate. But if a report is primarily a way to showcase a lot of code, with intermittent text, then spin can save you a lot of trouble.

Should you use {knitr} when working on a document?

Using {knitr} is no different. When you work on documents with different team members, it’s helpful to have a consistent set of settings. If the default for changes, this can easily waste time as you try to track down an error.


1 Answers

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
like image 94
Josh O'Brien Avatar answered Oct 16 '22 21:10

Josh O'Brien