Jupyter RMagic不会返回交互式R输出

时间:2017-10-17 12:13:40

标签: python r jupyter rpy2

根据the rpy2 docs,应该可以看到这样的交互式R输出:

%%R
X=c(1,4,5,7)
Y = c(2,4,3,9)
summary(lm(Y~X))

应该产生这个:

Call:
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

但是,尽管能够使用stuff like this SO answer从R返回漂亮的图形,但不会返回summary的R交互输出。

我可以通过以下方式解决这个问题:

In [75]: %%R -o return_value                                                  
       : X = c(1,4,5,7)                                              
       : Y = c(2,4,3,9)                                              
       : return_value = summary(lm(Y~X))                                            

然后像这样print返回的值(虽然输出看起来很糟糕,因为每个输出行之间有空行):

In [86]: print(return_value)


Call:

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

文档不正确,还是我做错了什么?

0 个答案:

没有答案