I need to make computations in a python program, and I would prefer to make some of them in R. Is it possible to embed R code in python ?
Advertisement
Answer
You should take a look at rpy (link to documentation here).
This allows you to do:
JavaScript
x
2
1
from rpy import *
2
And then you can use the object called r
to do computations just like you would do in R.
Here is an example extracted from the doc:
JavaScript
1
8
1
>>> from rpy import *
2
>>>
3
>>> degrees = 4
4
>>> grid = r.seq(0, 10, length=100)
5
>>> values = [r.dchisq(x, degrees) for x in grid]
6
>>> r.par(ann=0)
7
>>> r.plot(grid, values, type=’lines’)
8