The following steps worked for me with the Python version Python 3.7.6
.
- Upgrade your
pip
python -m pip install --upgrade pip
- Install
pyensae
module
pip install pyensae
- 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)