Search code examples
pythonrrpy2

Calling R options() function from rpy2


In R, options() function may be used, such as:

options(width=80)

For example, this changes the screen print width to 80 characters.

How to achieve similar using the rpy2 library in Python?

From rpy2 documentation (https://rpy2.github.io/doc/v2.9.x/html/rinterface.html), it seems the options are visible:

options = rinterface.globalenv.get("options")()

Solution

  • The documentation for the current release is probably a better source of information:

    https://rpy2.github.io/doc/v3.4.x/html/index.html

    There are a few ways to achieve this, and while the one you point out is one of them this is not the most obvious when not interested in the inner workings of rpy2 or in advanced tweaks.

    For example:

    import rpy2.robjects as robjects
    robjects.r("options(width=80)")
    

    Or

    from rpy2.robjects.packages import importr
    base = importr('base')
    base.options(width=80)