We can use any languages in knitr, including but not limited to R. Here are some simple demos with Python, Awk, Ruby, Haskell, Bash, Perl, Graphviz, TikZ, SAS, Scala, and CoffeeScript, etc:
- python.Rmd (output)
- c.Rmd (output)
- fortran.Rmd (output)
- sql.Rmd (output)
- awk.Rmd (output)
- ruby.Rmd (output)
- haskell.Rmd (output)
- bash.Rmd (output)
- perl.Rmd (output)
- dot.Rmd (output)
- tikz.Rmd (output)
- sas.Rmd (output)
- coffeescript.Rmd (output)
- polyglot.Rmd (output)
- Scala, Python, and Bash
These languages are easy to deal with because they can be called by pure
command line, e.g. python -c can execute the code passed in as a character
string.
The Rcpp engine is different, however. The C++ code is compiled through the
Rcpp package. See Rcpp.Rmd
(output)
for example. Similarly, C code is compiled via R CMD SHLIB
(example/output).
A special engine cat can be used to save the content of a code chunk to a
file using the cat() function; see the
example 095
for an application.
The object knit_engines stores a series of named
functions to handle code from different languages, and you are free to
define a function to deal with a custom language. See
engine.R for
examples on how I deal with Python and Awk.
I do not really know much about other languages, so please feel free to contribute more language engines to knitr.
Note these languages work not only in Markdown, but also in other formats like LaTeX.
Except engine='R' (default), all chunks are executed in separate sessions,
so the variables cannot be directly shared. If we want to make use of
objects created in previous chunks, we usually have to write them to files
(as side effects). For the bash engine, we can use Sys.setenv() to
export variables from R to bash (example).
For the sql and the stan engines, we can store the object as a variable
whose name is specified to the output.var chunk option. Another approach is to
use the (experimental) runr package.
Additional arguments can be passed to the engines via the engine.opts chunk
option. The option can be specified as a string (e.g., '-p') or as a list of
strings named by engines (e.g., list(perl = '-Mstrict -Mwarnings', bash = '-o errexit')).
The latter is useful to template arguments via knitr::opts_chunk$set().
For the cat engine, the code chunk can be displayed in the output if the chunk
language is specified via the engine.opts chunk option, e.g. engine.opts = list(lang = 'makefile').
For the tikz engine, the path to the convert utility of ImageMagick can be
specified via the engine.opts chunk option, e.g. engine.opts = list(convert = 'path/to/convert').
Similarly, more command line arguments to convert can be specified via, for
example, engine.opts = list(convert.opts = '-density 300').
Donate
As a freelancer (currently working as a contractor) and a dad of three kids, I truly appreciate your donation to support my writing and open-source software development! Your contribution helps me cope with financial uncertainty better, so I can spend more time on producing high-quality content and software. You can make a donation through methods below.
-
Venmo:
@yihui_xie, or Zelle:xie@yihui.name -
Paypal
-
If you have a Paypal account, you can follow the link https://paypal.me/YihuiXie or find me on Paypal via my email
xie@yihui.name. Please choose the payment type as “Family and Friends” (instead of “Goods and Services”) to avoid extra fees. -
If you don’t have Paypal, you may donate through this link via your debit or credit card. Paypal will charge a fee on my side.
-
-
Other ways:
WeChat Pay (微信支付:谢益辉) Alipay (支付宝:谢益辉) 

When sending money, please be sure to add a note “gift” or “donation” if possible, so it won’t be treated as my taxable income but a genuine gift. Needless to say, donation is completely voluntary and I appreciate any amount you can give.
Please feel free to email me if you prefer a different way to give. Thank you very much!
I’ll give back a significant portion of the donations to the open-source community and charities. For the record, I received about $30,000 in total (before tax) in 2024-25, and gave back about $15,000 (after tax).