Ejemplo n.º 1
0
from collections import namedtuple
from rpy2.robjects.packages import importr, data
import warnings
with warnings.catch_warnings():
    warnings.simplefilter("ignore")
    tidyr = importr('tidyr', on_conflict="warn")
    TARGET_VERSION = '0.3.1'
    if tidyr.__version__ != TARGET_VERSION:
        warnings.warn('This was designed againt tidyr version %s but you have %s' % (TARGET_VERSION, dplyr.__version__))

from rpy2.robjects.lib import dplyr

class DataFrame(dplyr.DataFrame):
    pass

DataFrame.summarize = dplyr._wrap(dplyr.summarize, DataFrame)
DataFrame.summarise = DataFrame.summarize

def _wrap(rfunc):
    def func(dataf, *args, **kwargs):
        cls = type(dataf)
        res = rfunc(dataf, *args, **kwargs)
        return cls(res)
    return func

DataFrame.gather = _wrap(tidyr.gather_)
DataFrame.spread = _wrap(tidyr.spread_)

Ejemplo n.º 2
0
if tidyr.__version__ != TARGET_VERSION:
    warnings.warn('This was designed againt tidyr version %s '
                  'but you have %s' % (TARGET_VERSION, tidyr.__version__))

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


def _wrap(rfunc):
    def func(dataf, *args, **kwargs):
        cls = type(dataf)
        res = rfunc(dataf, *args, **kwargs)
        return cls(res)

    return func


class DataFrame(dplyr.DataFrame):
    gather = _wrap(tidyr.gather)
    spread = _wrap(tidyr.spread)


DataFrame.summarize = dplyr._wrap(dplyr.summarize, None)
DataFrame.summarise = DataFrame.summarize
Ejemplo n.º 3
0
class DataFrame(dplyr.DataFrame):
    gather = _wrap(tidyr.gather)
    spread = _wrap(tidyr.spread)
    summarize = dplyr._wrap(dplyr.summarize, None)