Embed R code in python

0 votes
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 ?
Feb 11 in Python by ana1504.k
• 7,890 points
28 views

1 answer to this question.

0 votes
You can try this :

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’)
answered Feb 11 by SDeb
• 13,190 points

Related Questions In Python

0 votes
1 answer

How to Convert usual text to executable machine code in python

what you are looking for is a ...READ MORE

answered Oct 1, 2018 in Python by Priyaj
• 56,940 points
714 views
0 votes
1 answer

How to correctly return an a dictionary as an output in zappier code using python?

David here, from the Zapier Platform team. ...READ MORE

answered Dec 3, 2018 in Python by charlie_brown
• 7,720 points
138 views
0 votes
1 answer

How can I import tensorflow libraries in my Python code?

You are doing it wrong as tf is not ...READ MORE

answered Dec 31, 2018 in Python by charlie_brown
• 7,720 points
630 views
0 votes
1 answer
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 349 views
0 votes
1 answer

Execute PHP code in Python

Try the following Code: import subprocess # if the ...READ MORE

answered Dec 10, 2018 in Python by SDeb
• 13,190 points
1,960 views
0 votes
1 answer

Indentation of Python in Notepad++

To indent the block, select the entire ...READ MORE

answered Sep 18, 2018 in Python by SDeb
• 13,190 points
316 views