2
from pyensae.languages import r2python

print(r2python(rscript, pep8=True))

I have problems converting filename.R into pythonfilename.py because these libraries are not useful for converting as it generates the error 'module not found' even if I installed that module using:

pip install pyensae

5 Answers 5

6

The following steps worked for me with the Python version Python 3.7.6.

  1. Upgrade your pip
python -m pip install --upgrade pip
  1. Install pyensae module
pip install pyensae
  1. Check your python console by executing below import
from pyensae.languages import r2python

If you are facing

ModuleNotFoundError: No module named 'antlr4'

or facing

ModuleNotFoundError: No module named 'builtin'

then execute the below command

pip install antlr4-python3-runtime

After the above steps, I could able to convert the R script to the python language

rscript = """
nb=function(y=1930){
debut=1816
MatDFemale=matrix(D$Female,nrow=111)
colnames(MatDFemale)=(debut+0):198
cly=(y-debut+1):111
deces=diag(MatDFemale[:,cly[cly%in%1:199]])
return(c(B$Female[B$Year==y],deces))}
"""
from pyensae.languages import r2python
print(r2python(rscript, pep8=True))

Console output

ANTLR runtime and generated code versions disagree: 4.9.1!=4.8 ANTLR runtime and generated code versions disagree: 4.9.1!=4.8 from python2r_helper import make_tuple

def nb(y=1930):
    debut = 1816
    MatDFemale = matrix(D . Female, nrow=111)
    colnames(MatDFemale) .set(range((debut + 0), 198))
    cly = range((y - debut + 1), 111)
    deces = diag(MatDFemale[:, cly[set(cly) & set(range(1, 199))]])
    return make_tuple(B . Female[B . Year == y], deces)
Sign up to request clarification or add additional context in comments.

1 Comment

Suffering with this error !!!! NameError: name 'unicode' is not defined. Was getting this issue, It has been resolved through restart IDE.
1

The below code is working.

from pyensae.languages import rconverter
print(rconverter.r2python(rscript, pep8=True))

Comments

0

pyensae is no longer supported with python 2.7

Try pip3 install pyensae

3 Comments

Now this error pops up ` from builtin import unicode ModuleNotFoundError: No module named "builtin'' `
I believe the "builtin" module was renamed to "builtins" in Python 3. Find the file where the code "from builtin import unicode" is run, and change it to: "from builtins import unicode" Source: github.com/catboost/catboost/issues/953
from builtins import unicode ImportError: cannot import name 'unicode' from 'builtins' (unknown location)
0

I fixed this issue by using:

  1. python 3.7.6
  2. pip 22.1.2
  3. antlr4-python3-runtime 4.9

This answer comes from here.

Comments

0

simple you have to decrease pyensae version,

first install below version pyensae

pip install pyensae==1.3.825

# you will get autopep8 error, so install autope8 below version

pip install autopep8==1.7.0

Then Run below code it will work

rscript = """
    nb=function(y=1930){
    debut=1816
    MatDFemale=matrix(D$Female,nrow=111)
    colnames(MatDFemale)=(debut+0):198
    cly=(y-debut+1):111
    deces=diag(MatDFemale[:,cly[cly%in%1:199]])
    return(c(B$Female[B$Year==y],deces))}
"""

from pyensae.languages.rconverter import r2python
print(r2python(rscript, pep8 = True))

Output:

def nb(y=1930):
    debut = 1816
    MatDFemale = matrix(D . Female, nrow=111)
    colnames(MatDFemale) .set(range((debut + 0), 198))
    cly = range((y - debut + 1), 111)
    deces = diag(MatDFemale[:, cly[set(cly) & set(range(1, 199))]])
    return make_tuple(B . Female[B . Year == y], deces)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.