Python variables live across chunk boundaries.

x = 1
y = 2
print x
## 1
print y
## 2

Plots generated by matplotlib are properly displayed.

import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4])
plt.show()

plt.plot([1, 2, 3, 4])
plt.show()

Python can access objects available in the R environment.

x <- 1:5
y <- 6:10
print r.x
## [1, 2, 3, 4, 5]
print r['y']
## [6, 7, 8, 9, 10]
r.hello = "World"
r['answer'] = 42
print(hello)
## [1] "World"
print(answer)
## [1] 42

Arbitrary R code can be evaluated from Python.

mpg = r["mtcars$mpg[1:5]"]
print mpg
## [21.0, 21.0, 22.8, 21.4, 18.7]
y = "a,b,c".split(",")
print y
## ['a', 'b', 'c']
## Chunk with echo = FALSE
print "Chunk with results = 'hide'"
# We have set 'eval = FALSE' here
r["abc"] = 1
exists("abc", envir = globalenv())
## [1] FALSE

Respect the error=TRUE chunk option – allow execution even after a Python error occurs.

raise RuntimeError("oops!")
## RuntimeError: oops!
## 
## Detailed traceback: 
##   File "<string>", line 1, in <module>
print "This line is still reached."
## This line is still reached.