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:
from rpy import *
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:
>>> from rpy import * >>> >>> degrees = 4 >>> grid = r.seq(0, 10, length=100) >>> values = [r.dchisq(x, degrees) for x in grid] >>> r.par(ann=0) >>> r.plot(grid, values, type=’lines’)