I am implementing an algorithm which has a lot of formulas in knitr. So I define some functions in some code chunks with names in the pattern <<Fun_bar>>=@
, and define unit test in other code chunks with names in the pattern <<Test_foo>>=@
. Now, I only want to run the function definition code chunks. Is there any functionality that could only execute those code chunks with names starting with "Test" ?
Asked
Active
Viewed 486 times
2
1 Answers
3
You can set eval
to TRUE
dynamically for chunks with labels that match Test_
using option hooks, e.g.
<<setup, include=FALSE>>=
knitr::opts_hooks$set(eval = function(options) {
options$eval = grepl('^Test_', options$label)
options
})
@

Yihui Xie
- 28,913
- 23
- 193
- 419
-
Hi, Yihui, thanks for the answer. Do I miss something, I just paste your code into the setup chunk of me and I have a chunk named <
>=, but this chunk is still running when I run "run all" in Rstudio. Or do you mean , this only works when Rstudio knit the pdf? – sunxd Nov 16 '16 at 18:42