Example #1
0
def to_py(o, skip_list=False):
    """
        Converts to python object if possible. 
        Otherwise wraps in ROBjectWrapper
    """
    res = None
    try:
        rcls = o.do_slot("class")
        rcls = list(rcls)
    except LookupError as le:
        rcls = []

    try:
        rclass = list(o.rclass)
    except:
        rclass = []


    classes = rclass + rcls

    if isinstance(o, SexpVector) and len(classes) > 0:
        if 'xts' in classes:
            res = rconv.convert_xts_to_df(o)
        elif 'POSIXct' in classes:
            res = rconv.convert_posixct_to_index(o)
        elif 'logical' in classes:
            res = rcommon._convert_vector(o)

    if res is None and isinstance(o, DataFrame):
        res = rcommon.convert_robj(o) 

    if res is None and isinstance(o, ListVector) and not skip_list:
        res = convert_ListVector(o)

    if res is None:
        try:
            res = rcommon.convert_robj(o) # fallback to pandas
        except:
            pass

    try: 
        if len(res) == 1:
            return res[0]
    except:
        pass
        
    if res is None and isinstance(o, SexpVector):
        res = RObjectWrapper(o)

    if res is None:
        res = o

    return res
Example #2
0
    try:
        rclass = list(o.rclass)
    except:
        rclass = []


    classes = rclass + rcls

    if isinstance(o, SexpVector) and len(classes) > 0:
        if 'xts' in classes:
            res = rconv.convert_xts_to_df(o)
        elif 'POSIXct' in classes:
            res = rconv.convert_posixct_to_index(o)
        elif 'logical' in classes:
            res = rcommon._convert_vector(o)

    if res is None and isinstance(o, DataFrame):
        res = rcommon.convert_robj(o) 

    if res is None and isinstance(o, ListVector) and not skip_list:
        res = convert_ListVector(o)

    if res is None:
        try:
            res = rcommon.convert_robj(o) # fallback to pandas
        except:
            pass

    try: 
        if len(res) == 1: