I have done some analysis in a .Rmd file. I now want to use some objects that are created in this file in a report that I'm writing up as a .Rnw file. Since switching from Sweave to knittr as the weaving engine the following happens:
If i run the line purl(input = 'myfile.Rmd', output = 'myfile.R')
in the console, I get an .R file that only contains the R chunks from the .Rmd file. That is what I want.
If I put this line into the .Rnw file and knit it (the .Rnw file, that is) however, I do end up with a myfile.R
and no errors, but it is completely empty (except for one linebreak for some reason).
I have also tried to put knitr::opts_chunk$set(purl = TRUE)
and knit_hooks$set(purl = hook_purl)
in the .Rmd file and then use knit()
instead of purl()
in my .Rnw file, but the result is the same.
The following is a small example:
test.Rnw
\documentclass{article}
\begin{document}
<<test>>=
library(knitr)
purl(input = 'test.Rmd', output = 'test.R')
@
\end{document}
test.Rmd
```{r}
answer <- 42
``` #
(Ignore the #, I didn't know how else to make the ticks show up)
Expected Output:
## ------------------------------------------------------------------------
answer <- 42
Actual output:
Does anyone have experience with this? Is this a bug or am I missing something? Thank you for your help!