yihui/knitr — Issue #19: Specifying options at knit time
Author: halpo
Created: 2011-11-23 20:20:14+00:00
State: open

Sweave packages can specify options at compile time for certain options that the package supports, such as
````
> Sweave("test.Rnw", prefix.string="figures/fig")
Writing to file test.tex
Processing code chunks with options ...
1 : echo term verbatim (label = first)
2 : echo term verbatim (label = cachesomething)
3 : term verbatim pdf (label = plotit)

You can now run (pdf)latex on 'test.tex'
```
creates a tex document and places all figures in the figures directory with fig prefixed to the figure. I see no way to specify this in `knitr`
```
> knit("test.Rnw", prefix.string='figures/fig-')
Error in knit("test.Rnw", prefix.string = "figures/fig-") :
unused argument(s) (prefix.string = "figures/fig-")
```
knit maybe could accept extra arguments in the form of `knit(input, output, pattern, ...)` where `...` would be used to specify defaults that are then written over for file and chunk options.

This is extremely useful for specifying with a Makefile
```
%.tex:%Rnw
Rscript -e "library(knitr);knit('$^","$@", prefix.string='figures/$*-')"
```
Which creates a tex file but could also puts graphics in a specific graphics folder which helps with cleanup, and prefixes graphics with the filename stem to prevent naming collisions, very useful with automated reporting.

Preferably, I would like to see knitr accept anything as an option and either silently or with warning discard those not valid or not used by specific blocks.

Also as a note. Original Sweave allowed for options set through SWEAVE_OPTS environment variable, although not all extension packages use this, nor is is used very much be people in general I believe.