This is similar to How to source R Markdown file like `source('myfile.r')`? with the following difference: I want my markdown file to generate an R script for future sourcing. The previous question was interested in directly sourcing the markdown file (which doesn't seem easy to do at this point).
Compiling an .Rmd markdown file that generates a useable source R file is possible by including the following:
```{r, ignore = TRUE, include = FALSE}
knit('markdown_file.Rmd', 'source_file.R', tangle = T)
```
This creates a source_file.R perfectly fine BUT it contains the knit
call at the end. So when I source("source_file.R)
in a different script, it recreates and overwrites itself, which seems like bad practice. Is there anyway to tell knit
to ignore a chunk of code in the .Rmd file?