set_writeconsole() not working on Windows

Issue #125 open
Joris Van den Bossche created an issue

Coming from this IPython issue: https://github.com/ipython/ipython/issues/3100

When trying to set a user defined writeconsole function in Windows, as in the example given by the rpy2 documentation here: http://rpy.sourceforge.net/rpy2/doc-2.1/html/callbacks.html#write-console

import rpy2.rinterface as rinterface

rinterface.initr()

buf = []
def f(x):
    # function that append its argument to the list 'buf'
    buf.append(x)

# output from the R console will now be appended to the list 'buf'
rinterface.set_writeconsole(f)

date = rinterface.baseenv['date']
rprint = rinterface.baseenv['print']
rprint(date())

# the output is in our list (as defined in the function f above)
print(buf)

buf is an empty list, and does not contain the output as expected and stated in the example.

I am using IPython 0.13.1 (with Python 2.7.3 through Anaconda 1.4.0 64 bit) and rpy2 2.3.3 (installed using the binaries provided by Gohlke, which dit work!).

Comments (12)

  1. Laurent Gautier
    • changed status to open

    AFAIR, there are issues with all(*) callbacks under Windows (it has never been possible to set new ones).

    It does not have to stay this way, but that's a matter of getting support for Windows together.

    (*: write to console, select a file, etc...see the doc on callbacks)

  2. bbbruce NA

    I'm having success running the callbacks under windows, BUT you must initialize them before the initr(). On my Windows box, the code above works as long as you move initr() after set_writeconsole(). This has to do with the way R sets callbacks in Windows vs. unix-alikes.

  3. Laurent Gautier

    Good to hear. This is will solve some of the use cases, such as R GUIs and front ends written in R, and this should definitely find its place in the rpy2 documentation.

  4. Joris Van den Bossche reporter

    For me it does not seem to work. When I run the code above, but with just initr() after set_writeconsole(), I still get no output.

  5. Dav Clark

    There is continued discussion on the IPython issue tracker related to this issue, it seems:

    https://github.com/ipython/ipython/issues/3100

    In particular, discussion of using R's capture.output, or the captureOutput function from R.utils (which would have to be installed, but is apparently much faster).

    I don't have time to look at this right now (I'm still behind on even a simple doc push), but it seems like if anyone has figured out how to make this work in a reasonable way, they should make a pull-request!

  6. Laurent Gautier

    I have touched a bit the way output from the R console is handled (rev. 5aff227)

    There is a very small chance that this is fixing the issue, and a greater chance that I just broke things on Windows, in case anyone wants to try.

  7. janschulz

    I've installed 2.5.6 (wheel from cgohlke) and I still don't get output from this cell under windows7/ ipython notebook master from today:

    %%R 
    print("yeah")
    

    If you have anything I can try, just tell me, I would really like to get output back from R and I don't really want to switch to linux just for that... :-)

  8. Laurent Gautier

    Too bad. This did not fix it.

    Unfortunately I do not know what you should try beside regular troubleshooting with code.

  9. Log in to comment