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]