PypeR issue "global name 'dump_stdout' is not defined"

1.5k Views Asked by At

Hello and thanks in advance.

I am attempting to run a very simple code in Python using the PypeR module to run R scripts in my Python code:

#Writing Some Python Code to interface with R

from pyper import *
import sys
import os
import pandas
import glob
import subprocess
import numpy

outputs = runR("a <- 3; print(a+5)")

It results in the following error:

Traceback (most recent call last):
  File "C:/Users/gavefl1/Documents/GitHub/Git_R_Test/NewRepo_Python_R/Python_R/MasterFile.py", line 14, in <module>
    outputs = runR("a <- 3; print(a+5)")
  File "C:\Python27\lib\site-packages\pyper.py", line 793, in runR
    Robj = R(RCMD=Robj, max_len=max_len, use_numpy=use_numpy, use_pandas=use_pandas, use_dict=use_dict, host=host, user=user, ssh=ssh, dump_stdout=dump_stdout)
NameError: global name 'dump_stdout' is not defined

I've tried looking into the actual PypeR.py code, but as far as I can tell 'dump_stdout' is defined. My system specifications are below. Again thanks:

Windows 7 64 Bit Python 2.7.8 Visual Studio 2008 (I've read this is the best Visual Studio Pack to run with Python) R 3.1.1 PypeR 1.1.2

1

There are 1 best solutions below

0
On

I think your example came from here: http://www.jstatsoft.org/v35/c02/paper

That article was published in 2010 and most likely corresponds to v1.0 https://pypi.python.org/pypi/PypeR/1.0

You can install pyper v.1.0 as follows.

pip uninstall pyper
pip install pyper==1.0

That being said you can achieve the same results with the current version (1.1.2) by doing the following:

>>> r = R()
>>> outputs = r.("a <- 3; print(a+5)")
>>> outputs
'try({a <- 3; print(a+5)})\n[1] 8\n'

With version 1.0 the result was:

>>> outputs = runR('a <- 3; print(a+5)')
>>> outputs
'try({a <- 3; print(a+5)})\n[1] 8\n'