简体   繁体   中英

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")()

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM