Divert output of specific chunks to separate file?

10 views
Skip to first unread message

joann....@vanderbilt.edu

unread,
Apr 8, 2016, 2:00:53 PM4/8/16
to knitr
I'm using knitr to make .tex files. I'm making really long reports, but I'd like to be able flag certain chunks to send their output to a separate file. Ideally, I want to be able to put all of these selected chunks into one separate tex file. I just realized that there is the split chunk option. I tried that, but it is sending the output to the dir in my fig.path.

Is there a way to set a separate directory for output that comes from chunks that use split? 

Is there a way to put all of these into one separate tex file? Essentially this would be creating 2 separate documents at the same time.

Thanks.

Yihui Xie

unread,
Apr 8, 2016, 2:12:22 PM4/8/16
to JoAnn Alvarez, knitr
You can redefine the output hook named `chunk` to do whatever you want
to: http://yihui.name/knitr/hooks/ e.g.

local({
hook_chunk = knitr::knit_hooks$get('chunk')
knitr::knit_hooks$set(chunk = function(x, options) {
out = hook_chunk(x, options)
writeLines(out, 'your_file.tex')
})
})

Regards,
Yihui
--
Yihui Xie <xiey...@gmail.com>
Web: http://yihui.name
Reply all
Reply to author
Forward
0 new messages