Search code examples
pythonrrpy2xtable

Generating LaTeX tables from R summary with RPy and xtable


I am running a few linear model fits in python (using R as a backend via RPy) and I would like to export some LaTeX tables with my R "summary" data.

This thread explains quite well how to do it in R (with the xtable function), but I cannot figure out how to implement this in RPy.

The only relevant thing searches such as "Chunk RPy" or "xtable RPy" returned was this, which seems to load the package in python but not to use it :-/

Here's an example of how I use RPy and what happens.

And this would be the error without bothering to load any data:

from rpy2.robjects.packages import importr
xtable = importr('xtable')
latex = xtable('')

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-131-8b38f31b5bb9> in <module>()
----> 1 latex = xtable(res_sum)
  2 print latex

TypeError: 'SignatureTranslatedPackage' object is not callable

I have tried using the stargazer package instead of xtable and I get the same error.


Solution

  • Ok, I solved it, and I'm a bit ashamed to say that it was a total no-brainer.

    You just have to call the functions as xtable.xtable() or stargazer.stargazer().