Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
74 lines (50 sloc) 1.38 KB

R works, of course.

library(knitr)
set.seed(123)
rnorm(5)

Does knitr work with Python? Use the chunk option engine='python':

x = 'hello, python world!'
print(x)
print(x.split(' '))

Or use the syntax ```{python}:

x = 'hello, python world!'
print(x.split(' '))

If all the chunks below are python chunks, we can set the engine globally:

opts_chunk$set(engine = 'python')

Chunk Options

You can use some chunk options like eval, echo and results. For example, eval=FALSE (do not evaluate code):

or echo=FALSE (hide source code):

or results='hide':

or results='asis':

print '**Write** _something_ in `Markdown` from `Python`!'

You can also cache the computation:

import time
# pretend this is a time-consuming task...
time.sleep(10)
print(1+1)

Strict Markdown

You can use strict markdown (i.e. indent by 4 spaces) by setting render_markdown(TRUE).

render_markdown(TRUE)

Now see how the output is changed: