Created
October 8, 2018 10:09
-
-
Save aoles/bf4ce1c881c6dcda4ac1833b20de1ed1 to your computer and use it in GitHub Desktop.
Save bash code chunks in R Markdown documents into separate script files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
output: html_document | |
--- | |
```{r setup, include=FALSE} | |
knit_hooks_source <- knitr::knit_hooks$get("source") | |
knitr::knit_hooks$set(source = function (x, options) { | |
if (!is.null(options$save)) | |
writeLines(x, options$save) | |
knit_hooks_source(x, options) | |
}) | |
knitr::opts_hooks$set(engine = function(options) { | |
if (options$engine == "bash") { | |
options$eval <- FALSE | |
options$save <- paste0(options$label, ".sh") | |
} | |
options | |
}) | |
``` | |
```{bash hello} | |
#!/bin/bash | |
echo "Hello World!" | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment