示例#1
0
文件: ggplot2.py 项目: rs2/rpy2
import rpy2.robjects.constants
import rpy2.robjects.conversion as conversion
from rpy2.robjects.packages import importr, WeakPackage
import copy
import warnings

NULL = robjects.NULL

rlang = importr('rlang', on_conflict='warn')
lazyeval = importr('lazyeval', on_conflict='warn')
base = importr('base', on_conflict='warn')
ggplot2 = importr('ggplot2', on_conflict='warn')
ggplot2 = WeakPackage(ggplot2._env,
                      ggplot2.__rname__,
                      translation=ggplot2._translation,
                      exported_names=ggplot2._exported_names,
                      on_conflict="warn",
                      version=ggplot2.__version__,
                      symbol_r2python=ggplot2._symbol_r2python,
                      symbol_check_after=ggplot2._symbol_check_after)

TARGET_VERSION = '3.2.0'
if ggplot2.__version__ != TARGET_VERSION:
    warnings.warn('This was designed againt ggplot2 version %s but you '
                  'have %s' % (TARGET_VERSION, ggplot2.__version__))
ggplot2_env = robjects.baseenv['as.environment']('package:ggplot2')

StrVector = robjects.StrVector


def as_symbol(x):
    return rlang.sym(x)
示例#2
0
from rpy2.robjects.packages import (importr, WeakPackage)
import warnings

with warnings.catch_warnings():
    warnings.simplefilter("ignore")
    dbplyr = importr('dbplyr', on_conflict="warn")
    dbplyr = WeakPackage(dbplyr._env,
                         dbplyr.__rname__,
                         translation=dbplyr._translation,
                         exported_names=dbplyr._exported_names,
                         on_conflict="warn",
                         version=dbplyr.__version__,
                         symbol_r2python=dbplyr._symbol_r2python,
                         symbol_check_after=dbplyr._symbol_check_after)
TARGET_VERSION = '1.2.1'
if dbplyr.__version__ != TARGET_VERSION:
    warnings.warn('This was designed against dbplyr version %s '
                  'but you have %s' % (TARGET_VERSION, dbplyr.__version__))

sql = dbplyr.sql
示例#3
0
"""

import rpy2.robjects as robjects
import rpy2.robjects.conversion as conversion
from rpy2.rlike.container import OrdDict
from rpy2.robjects.packages import importr, WeakPackage

NULL = robjects.NULL

grid = importr('grid')

grid = WeakPackage(grid._env,
                   grid.__rname__,
                   translation=grid._translation,
                   exported_names=grid._exported_names,
                   on_conflict="warn",
                   version=grid.__version__,
                   symbol_r2python=grid._symbol_r2python,
                   symbol_resolve=grid._symbol_resolve)

grid_env = robjects.baseenv['as.environment']('package:grid')


layout = grid.grid_layout
newpage = grid.grid_newpage
grill = grid.grid_grill
edit = grid.grid_edit
get = grid.grid_get
remove = grid.grid_remove
add = grid.grid_add
xaxis = grid.grid_xaxis
示例#4
0
文件: dplyr.py 项目: quantForma/rpy2
from collections import namedtuple
from rpy2 import robjects
from rpy2.robjects.packages import (importr,
                                    WeakPackage)
import warnings

with warnings.catch_warnings():
    warnings.simplefilter("ignore")
    dplyr_ = importr('dplyr', on_conflict="warn")
    lazyeval = importr('lazyeval', on_conflict="warn")
    rlang = importr('rlang', on_conflict='warn',
                    robject_translations={'.env': '__env'})
    dplyr = WeakPackage(dplyr_._env,
                        dplyr_.__rname__,
                        translation=dplyr_._translation,
                        exported_names=dplyr_._exported_names,
                        on_conflict="warn",
                        version=dplyr_.__version__,
                        symbol_r2python=dplyr_._symbol_r2python,
                        symbol_resolve=dplyr_._symbol_resolve)

TARGET_VERSION = '0.8.'
if not dplyr.__version__.startswith(TARGET_VERSION):
    warnings.warn(
        'This was designed againt dplyr versions starting with %s'
        ' but you have %s' %
        (TARGET_VERSION, dplyr.__version__))

StringInEnv = namedtuple('StringInEnv', 'string env')


def _fix_args_inenv(args, env):
示例#5
0
import warnings
with warnings.catch_warnings():
    warnings.simplefilter("ignore")
    Matrix_pack = importr('Matrix', on_conflict="warn")

TARGET_VERSION = '1.2-'

if not Matrix_pack.__version__.startswith(TARGET_VERSION):
    warnings.warn('This was designed to match Matrix version starting with %s '
                  'but you have %s' %
                  (TARGET_VERSION, Matrix_pack.__version__))

Matrix_weakpack = WeakPackage(Matrix_pack._env,
                              Matrix_pack.__rname__,
                              translation=Matrix_pack._translation,
                              exported_names=Matrix_pack._exported_names,
                              on_conflict="warn",
                              version=Matrix_pack.__version__,
                              symbol_r2python=Matrix_pack._symbol_r2python,
                              symbol_resolve=Matrix_pack._symbol_resolve)


class RS4Vector(rpy2.robjects.methods.RS4):
    """Base class for RS4 objects with the behavior of base R vectors."""
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.ro = vectors.VectorOperationsDelegator(self)
        self.rx = vectors.ExtractDelegator(self)


def _setExtractDelegators(self):
    self.rx = vectors.ExtractDelegator(self)
示例#6
0
文件: grid.py 项目: bbgw/rpy2
The R library provides a low-level coordinate
system and graphic primitives to built visualizations.


"""

import rpy2.robjects as robjects
import rpy2.robjects.conversion as conversion
from rpy2.rlike.container import OrdDict
from rpy2.robjects.packages import importr, WeakPackage

NULL = robjects.NULL

grid = importr('grid')

grid = WeakPackage(grid)

grid_env = robjects.baseenv['as.environment']('package:grid')

layout = grid.grid_layout
newpage = grid.grid_newpage
grill = grid.grid_grill
edit = grid.grid_edit
get = grid.grid_get
remove = grid.grid_remove
add = grid.grid_add
xaxis = grid.grid_xaxis
yaxis = grid.grid_yaxis


class Unit(robjects.RObject):
示例#7
0
import typing
import warnings
with warnings.catch_warnings():
    warnings.simplefilter('ignore')
    R6_pack = importr('R6', on_conflict='warn')

TARGET_VERSION = '2.5.'

if not R6_pack.__version__.startswith(TARGET_VERSION):
    warnings.warn('This was designed to match R6 version starting with %s '
                  'but you have %s' % (TARGET_VERSION, R6_pack.__version__))

R6_weakpack = WeakPackage(R6_pack._env,
                          R6_pack.__rname__,
                          translation=R6_pack._translation,
                          exported_names=R6_pack._exported_names,
                          on_conflict='warn',
                          version=R6_pack.__version__,
                          symbol_r2python=R6_pack._symbol_r2python,
                          symbol_resolve=R6_pack._symbol_resolve)

dollar = rpy2_R6.utils.dollar

# This will map an `rid` (identifier for an R object of class
# R6ClassGenerator) to a Python class inheriting from R6.
_CLASSMAP = dict()


def _static_classmap(clsgenerator: 'R6ClassGenerator') -> typing.Type['R6']:
    return _CLASSMAP.get(clsgenerator.rid, R6)

示例#8
0
文件: grdevices.py 项目: bbgw/rpy2
"""
Mapping of the R library "grDevices" for graphical devices
"""

import io
import os
import tempfile
from contextlib import contextmanager
from rpy2.robjects.packages import importr, WeakPackage

grdevices = importr('grDevices')

grdevices = WeakPackage(grdevices)

# non-interactive file devices
png = grdevices.png
jpeg = grdevices.jpeg
bmp = grdevices.bmp
tiff = grdevices.tiff

svg = grdevices.svg

postscript = grdevices.postscript
pdf = grdevices.pdf
cairo_pdf = grdevices.cairo_pdf

#
X11 = grdevices.X11

# OS X
quartz = grdevices.quartz
示例#9
0
from collections import namedtuple
from rpy2 import robjects
from rpy2.robjects.packages import (importr,
                                    WeakPackage)
import warnings

with warnings.catch_warnings():
    warnings.simplefilter("ignore")
    dplyr_ = importr('dplyr', on_conflict="warn")
    lazyeval = importr('lazyeval', on_conflict="warn")
    rlang = importr('rlang', on_conflict='warn',
                    robject_translations={'.env': '__env'})
    dplyr = WeakPackage(dplyr_)

TARGET_VERSION = '0.8.'
if not dplyr.__version__.startswith(TARGET_VERSION):
    warnings.warn(
        'This was designed againt dplyr versions starting with %s'
        ' but you have %s' %
        (TARGET_VERSION, dplyr.__version__))

StringInEnv = namedtuple('StringInEnv', 'string env')


def _fix_args_inenv(args, env):
    """Use R's lazyeval::as_lazy to evaluate each argument in a sequence as
    code in an environment."""
    args_inenv = list()
    for v in args:
        if isinstance(v, StringInEnv):
            args_inenv.append(lazyeval.as_lazy(v.string, env=v.env))
示例#10
0
文件: dbplyr.py 项目: bbgw/rpy2
from rpy2.robjects.packages import (importr, WeakPackage)
import warnings

with warnings.catch_warnings():
    warnings.simplefilter("ignore")
    dbplyr = importr('dbplyr', on_conflict="warn")
    dbplyr = WeakPackage(dbplyr)
TARGET_VERSION = '1.4.2'
if dbplyr.__version__ != TARGET_VERSION:
    warnings.warn('This was designed against dbplyr version %s '
                  'but you have %s' % (TARGET_VERSION, dbplyr.__version__))

sql = dbplyr.sql
示例#11
0
文件: ggplot2.py 项目: bbgw/rpy2
import rpy2.robjects as robjects
import rpy2.robjects.constants
import rpy2.robjects.conversion as conversion
from rpy2.robjects.packages import importr, WeakPackage
import copy
import warnings

NULL = robjects.NULL

rlang = importr('rlang',
                on_conflict='warn',
                robject_translations={'.env': '__env'})
lazyeval = importr('lazyeval', on_conflict='warn')
base = importr('base', on_conflict='warn')
ggplot2 = importr('ggplot2', on_conflict='warn')
ggplot2 = WeakPackage(ggplot2)

TARGET_VERSION = '3.3.'
if not ggplot2.__version__.startswith(TARGET_VERSION):
    warnings.warn(
        'This was designed againt ggplot2 versions starting with %s but you '
        'have %s' % (TARGET_VERSION, ggplot2.__version__))
ggplot2_env = robjects.baseenv['as.environment']('package:ggplot2')

StrVector = robjects.StrVector


def as_symbol(x):
    return rlang.sym(x)