Rmagic on Windows: no text output is shown #3100

Open
jorisvandenbossche opened this Issue Mar 27, 2013 · 17 comments

Comments

Projects
None yet
9 participants
@jorisvandenbossche
Contributor

jorisvandenbossche commented Mar 27, 2013

When using the rmagic on Windows, I get no text output in the notebook. Eg if I run

%%R
x <- c(0,1,2,3,4)
print(x)

no output is written in the output area of the notebook (except from the blank figure). However, the output is written in the console where I started ipython notebook.

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!).

I splitted this from issue #3098 because I think it is a seperate issue.

@jorisvandenbossche

This comment has been minimized.

Show comment Hide comment
@jorisvandenbossche

jorisvandenbossche Mar 27, 2013

Contributor

I searched a bit for a possible reason, and it seems text_output (here) always stays an empty string (when you let the magic print it). So the flush function (here) does not do its job, probably because Rstdout_cache stays empty in the write_console function (here).

So the mechanism of rpy2 to set a user defined writeconsole function does not work on Windows.
I also tried it outside of IPython notebook/rmagic with 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)

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

Contributor

jorisvandenbossche commented Mar 27, 2013

I searched a bit for a possible reason, and it seems text_output (here) always stays an empty string (when you let the magic print it). So the flush function (here) does not do its job, probably because Rstdout_cache stays empty in the write_console function (here).

So the mechanism of rpy2 to set a user defined writeconsole function does not work on Windows.
I also tried it outside of IPython notebook/rmagic with 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)

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

@takluyver

This comment has been minimized.

Show comment Hide comment
@takluyver

takluyver Mar 27, 2013

Member

It's worth noting that rpy2 often hasn't been as well supported on Windows as it is on *nix systems - it's primarily maintained by one author, Laurent, who doesn't use Windows, and apparently there are some differences in how R works on Windows.

If you think there's an issue in rpy2 itself, its code and issue tracker are at https://bitbucket.org/lgautier/rpy2

Member

takluyver commented Mar 27, 2013

It's worth noting that rpy2 often hasn't been as well supported on Windows as it is on *nix systems - it's primarily maintained by one author, Laurent, who doesn't use Windows, and apparently there are some differences in how R works on Windows.

If you think there's an issue in rpy2 itself, its code and issue tracker are at https://bitbucket.org/lgautier/rpy2

@jorisvandenbossche

This comment has been minimized.

Show comment Hide comment
@jorisvandenbossche

jorisvandenbossche Apr 29, 2013

Contributor

A question: as the output is shown in the console where you start the ipython notebook, would it be possible to 'capture' this output there and still print it this way in the notebook output?

To be clear, I don't propose this as a solution, but maybe it could provide a quick hack for personal use to be able to use the rmagic on windows.

Contributor

jorisvandenbossche commented Apr 29, 2013

A question: as the output is shown in the console where you start the ipython notebook, would it be possible to 'capture' this output there and still print it this way in the notebook output?

To be clear, I don't propose this as a solution, but maybe it could provide a quick hack for personal use to be able to use the rmagic on windows.

@takluyver

This comment has been minimized.

Show comment Hide comment
@takluyver

takluyver Apr 29, 2013

Member

Might be - have a look at #1230

Member

takluyver commented Apr 29, 2013

Might be - have a look at #1230

@Thwiouz

This comment has been minimized.

Show comment Hide comment
@Thwiouz

Thwiouz Nov 13, 2013

Hi,
Does someone have news for any fix for the stdout error in Notebooks (in Windows)?

Cheers

Thwiouz commented Nov 13, 2013

Hi,
Does someone have news for any fix for the stdout error in Notebooks (in Windows)?

Cheers

@Thwiouz

This comment has been minimized.

Show comment Hide comment
@Thwiouz

Thwiouz Nov 18, 2013

Hi @jorisvandenbossche
Could you find a solution for the problem you mentionned?

Thanks;

Thwiouz commented Nov 18, 2013

Hi @jorisvandenbossche
Could you find a solution for the problem you mentionned?

Thanks;

@jorisvandenbossche

This comment has been minimized.

Show comment Hide comment
@jorisvandenbossche

jorisvandenbossche Nov 19, 2013

Contributor

No, I didn't dig in it further, and didn't found a solution. Problem is that Windows is not really fully supported by rpy2.

But I also think the rmagic is now further developed within rpy2 itself

Contributor

jorisvandenbossche commented Nov 19, 2013

No, I didn't dig in it further, and didn't found a solution. Problem is that Windows is not really fully supported by rpy2.

But I also think the rmagic is now further developed within rpy2 itself

@Thwiouz

This comment has been minimized.

Show comment Hide comment
@Thwiouz

Thwiouz Nov 20, 2013

Ok thank you.
Maybe I'll ask to Laurent Gautier if he has some news about that.

Thwiouz commented Nov 20, 2013

Ok thank you.
Maybe I'll ask to Laurent Gautier if he has some news about that.

@zhangruoyu

This comment has been minimized.

Show comment Hide comment
@zhangruoyu

zhangruoyu Apr 3, 2014

I think the problem can be solve by using capture.output() in R.

I think the problem can be solve by using capture.output() in R.

@takluyver

This comment has been minimized.

Show comment Hide comment
@takluyver

takluyver Apr 3, 2014

Member

rmagic is becoming part of rpy2. Pinging @davclark to make sure he's seen this.

Member

takluyver commented Apr 3, 2014

rmagic is becoming part of rpy2. Pinging @davclark to make sure he's seen this.

@stonebig

This comment has been minimized.

Show comment Hide comment
@stonebig

stonebig Oct 9, 2014

Contributor
%%R
X=c(1,4,5,7);Y = c(2,4,3,9)
s <- capture.output({summary(lm(Y~X)) })
a =%R s
for line in a[2:-1]:
         print(line )

lm(formula = Y ~ X)

Residuals:
1 2 3 4
0.88 -0.24 -2.28 1.64

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.0800 2.3000 0.035 0.975
X 1.0400 0.4822 2.157 0.164

Residual standard error: 2.088 on 2 degrees of freedom
Multiple R-squared: 0.6993, Adjusted R-squared: 0.549
F-statistic: 4.651 on 1 and 2 DF, p-value: 0.1638

Contributor

stonebig commented Oct 9, 2014

%%R
X=c(1,4,5,7);Y = c(2,4,3,9)
s <- capture.output({summary(lm(Y~X)) })
a =%R s
for line in a[2:-1]:
         print(line )

lm(formula = Y ~ X)

Residuals:
1 2 3 4
0.88 -0.24 -2.28 1.64

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.0800 2.3000 0.035 0.975
X 1.0400 0.4822 2.157 0.164

Residual standard error: 2.088 on 2 degrees of freedom
Multiple R-squared: 0.6993, Adjusted R-squared: 0.549
F-statistic: 4.651 on 1 and 2 DF, p-value: 0.1638

@stonebig

This comment has been minimized.

Show comment Hide comment
@stonebig

stonebig Oct 9, 2014

Contributor

or, as suggested there for performance (and it doesn't seem to write anymore on DOS)
http://www.r-bloggers.com/performance-captureoutput-is-much-faster-than-capture-output/

%R install.packages("R.utils")
%R library(R.utils)

array(['R.utils', 'R.oo', 'R.methodsS3', 'tools', 'stats', 'graphics',
'grDevices', 'utils', 'datasets', 'methods', 'base'],
dtype='<U11')

%%R
X=c(1,4,5,7);Y = c(2,4,3,9)
s <- captureOutput({summary(lm(Y~X)) })
a =%R s
for line in a[2:-1]:
         print(line )

lm(formula = Y ~ X)

Residuals:
1 2 3 4
0.88 -0.24 -2.28 1.64

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.0800 2.3000 0.035 0.975
X 1.0400 0.4822 2.157 0.164

Residual standard error: 2.088 on 2 degrees of freedom
Multiple R-squared: 0.6993, Adjusted R-squared: 0.549
F-statistic: 4.651 on 1 and 2 DF, p-value: 0.1638

Contributor

stonebig commented Oct 9, 2014

or, as suggested there for performance (and it doesn't seem to write anymore on DOS)
http://www.r-bloggers.com/performance-captureoutput-is-much-faster-than-capture-output/

%R install.packages("R.utils")
%R library(R.utils)

array(['R.utils', 'R.oo', 'R.methodsS3', 'tools', 'stats', 'graphics',
'grDevices', 'utils', 'datasets', 'methods', 'base'],
dtype='<U11')

%%R
X=c(1,4,5,7);Y = c(2,4,3,9)
s <- captureOutput({summary(lm(Y~X)) })
a =%R s
for line in a[2:-1]:
         print(line )

lm(formula = Y ~ X)

Residuals:
1 2 3 4
0.88 -0.24 -2.28 1.64

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.0800 2.3000 0.035 0.975
X 1.0400 0.4822 2.157 0.164

Residual standard error: 2.088 on 2 degrees of freedom
Multiple R-squared: 0.6993, Adjusted R-squared: 0.549
F-statistic: 4.651 on 1 and 2 DF, p-value: 0.1638

@davclark

This comment has been minimized.

Show comment Hide comment
@davclark

davclark Oct 9, 2014

Contributor

I linked to this issue here:

https://bitbucket.org/lgautier/rpy2/issue/125/set_writeconsole-not-working-on-windows

I hadn't realized that this was still an issue.

Contributor

davclark commented Oct 9, 2014

I linked to this issue here:

https://bitbucket.org/lgautier/rpy2/issue/125/set_writeconsole-not-working-on-windows

I hadn't realized that this was still an issue.

@jankatins

This comment has been minimized.

Show comment Hide comment
@jankatins

jankatins Feb 11, 2015

Contributor

The new home for the issue on Rpy2 side is https://bitbucket.org/rpy2/rpy2/issue/125/set_writeconsole-not-working-on-windows

Just got bitten by this as well, it's still happening with rpy2 2.5.6 :-(

Contributor

jankatins commented Feb 11, 2015

The new home for the issue on Rpy2 side is https://bitbucket.org/rpy2/rpy2/issue/125/set_writeconsole-not-working-on-windows

Just got bitten by this as well, it's still happening with rpy2 2.5.6 :-(

@mygitjunk

This comment has been minimized.

Show comment Hide comment
@mygitjunk

mygitjunk Apr 5, 2015

I hacked Fernando's pseudo-R kernel to address this matter using suggestion from stonebig.
https://github.com/mygitjunk/ipython-rkernel

Cheers!

I hacked Fernando's pseudo-R kernel to address this matter using suggestion from stonebig.
https://github.com/mygitjunk/ipython-rkernel

Cheers!

@Carreau

This comment has been minimized.

Show comment Hide comment
@Carreau

Carreau Apr 5, 2015

Member

@mygitjunk I think you want to contribute the the R kernel which is here: https://github.com/IRkernel/IRkernel

Member

Carreau commented Apr 5, 2015

@mygitjunk I think you want to contribute the the R kernel which is here: https://github.com/IRkernel/IRkernel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment