Collection of Language Engines for Use with the ‘knitr’ Package
The knitr package lets you use other languages in knitr ‘chunks’. This package is a collection of languages processors not built-in with knitr.
The following functions are implemented:
knitr_cawk_engine
: knitr engine for the CSV-enhanced Awk languageknitr_elixir_engine
: knitr engine for the Elixir languageknitr_gnuplot_engine
: knitr engine for the Go languageknitr_pygments_engine
: knitr engine for the pygments syntax highlighting (w/o execution)
knitrengines
is package to collect and seamlessly add new language
engines to knitr
You can thank Wendy Smoak for this package as a comment on a DDS post sparked it.
The knitr package already has support for a plethora of languages besides R code chunks (26 as of the last update to this package). That is probably sufficient for the vast majority of users.
However, if you need to perform some processing in another languages and want to include it in your reproducible workflow, this package will allow you to incorporate those language code chunks provided there is a matching knitr language processor available.
To use one of these alternate code chunks, just ensure you have a call
to library(knitrengines)
in an R code chunk at/near the top of your R
markdown file then use one of the available engines via the short name
below as the package will auto-register them on attach.
This package contains support for the following engines:
cawk
: Support for Awk builds that include CSV support (see?knitr_cawk_engine
).elixir
: Elixir language supportpygments
: Use pygments to stylize non-executable code blocks. Seeknitrengines::knitr_pygments_engine
for all the “gotchas”gnuplot
: Use gnuplot for plotting
You can contribe to the project and add support for other language code chunks by:
- forking this repo
- adding a new
xyz_engine.r
under theR
directory ensuring you add yourself as an@author
- adding that engine to the list in
zzz.r
- update
DESCRIPTION
and add yourself as a contributor and update the third dottedn number in the version string (i.e. 0.2.0 -> 0.2.1) - update
inst/examples/knitr_engine_test.Rmd
and add a (small) example of your engine - update the
README.Rmd
to include your new engine. - submit a PR
The only real downside is that these language chunks do not have access to the variables in/across chunks, so you have to export the data from previous chunks to files (or databases, etc.) to access it (if needed).
Before you go creating other engines, these are the ones knitr already:
sort(names(knitr::knit_engines$get()))
## [1] "asis" "asy" "awk" "bash" "block" "block2" "bslib" "c" "cat"
## [10] "cc" "coffee" "comment" "css" "ditaa" "dot" "embed" "exec" "fortran"
## [19] "fortran95" "gawk" "glue" "glue_sql" "gluesql" "go" "groovy" "haskell" "highlight"
## [28] "js" "julia" "lein" "mermaid" "mysql" "node" "octave" "ojs" "perl"
## [37] "psql" "python" "R" "Rcpp" "Rscript" "ruby" "sas" "sass" "scala"
## [46] "scss" "sed" "sh" "sql" "stan" "stata" "targets" "tikz" "verbatim"
## [55] "zsh"
remotes::install_github("hrbrmstr/knitrengines")
NOTE: To use the ‘remotes’ install options you will need to have the {remotes} package installed.