Esempio n. 1
0
def eval(x, envir=ri.globalenv):
    """ Evaluate R code. If the input object is an R expression it
    evaluates it directly, if it is a string it parses it before 
    evaluating it.

    By default the evaluation is performed in R's global environment
    but a specific environment can be specified."""
    if isinstance(x, str) or isinstance(x, unicode):
        p = _parse(x)
    else:
        p = x
    res = _reval(p, envir=envir)
    res = conversion.ri2ro(res)
    return res
Esempio n. 2
0
def eval(x, envir = ri.globalenv):
    """ Evaluate R code. If the input object is an R expression it
    evaluates it directly, if it is a string it parses it before 
    evaluating it.

    By default the evaluation is performed in R's global environment
    but a specific environment can be specified."""
    if isinstance(x, str) or isinstance(x, unicode):
        p = _parse(x)
    else:
        p = x
    res = _reval(p, envir = envir)
    res = conversion.ri2ro(res)
    return res
Esempio n. 3
0
def set_accessors(cls, cls_name, where, acs):
    # set accessors (to be abandonned for the metaclass above ?)

    if where is None:
        where = rinterface.globalenv
    else:
        where = "package:" + str(where)
        where = StrSexpVector((where, ))

    for r_name, python_name, as_property, docstring in acs:
        if python_name is None:
            python_name = r_name
        r_meth = getmethod(StrSexpVector((r_name, )), 
                           signature = StrSexpVector((cls_name, )),
                           where = where)
        r_meth = conversion.ri2ro(r_meth)
        if as_property:
            setattr(cls, python_name, property(r_meth, None, None))
        else:
            setattr(cls, python_name, lambda self: r_meth(self))
Esempio n. 4
0
    def __new__(mcs, name, bases, cls_dict):

        try:
            cls_rname = cls_dict['__rname__']
        except KeyError as ke:
            cls_rname = name

        try:
            accessors = cls_dict['__accessors__']
        except KeyError as ke:
            accessors = []
            
        for rname, where, \
                python_name, as_property, \
                docstring in accessors:

            if where is None:
                where = rinterface.globalenv
            else:
                where = "package:" + str(where)
                where = StrSexpVector((where, ))

            if python_name is None:
                python_name = rname
                
            signature = StrSexpVector((cls_rname, ))            
            r_meth = getmethod(StrSexpVector((rname, )), 
                               signature = signature,
                               where = where)
            r_meth = conversion.ri2ro(r_meth)
            if as_property:
                cls_dict[python_name] = property(r_meth, None, None,
                                                 doc = docstring)
            else:
                cls_dict[python_name] =  lambda self: r_meth(self)
                
        return type.__new__(mcs, name, bases, cls_dict)
Esempio n. 5
0
 def do_slot(self, name):
     return conversion.ri2ro(super(RS4, self).do_slot(name))