Exemplo n.º 1
0
    def __call__(self, *args, **kwargs):
        """ Subset the "R-way.", using R's "[" function. 
           In a nutshell, R indexing differs from Python indexing on:

           - indexing can be done with integers or strings (that are 'names')

           - an index equal to TRUE will mean everything selected
             (because of the recycling rule)

           - integer indexing starts at one

           - negative integer indexing means exclusion of the given integers

           - an index is itself a vector of elements to select
        """

        args = [conversion.py2ro(x) for x in args]
        kwargs = copy.copy(kwargs)
        for k, v in kwargs.itervalues():
            kwargs[k] = conversion.py2ro(v)
        fun = self._extractfunction
        args.insert(0, self._parent)
        res = fun(*args, **kwargs)
        res = conversion.py2ro(res)
        return res
Exemplo n.º 2
0
    def __call__(self, *args, **kwargs):
        """ Subset the "R-way.", using R's "[" function. 
           In a nutshell, R indexing differs from Python indexing on:

           - indexing can be done with integers or strings (that are 'names')

           - an index equal to TRUE will mean everything selected
             (because of the recycling rule)

           - integer indexing starts at one

           - negative integer indexing means exclusion of the given integers

           - an index is itself a vector of elements to select
        """

        args = [conversion.py2ro(x) for x in args]
        kwargs = copy.copy(kwargs)
        for k, v in kwargs.itervalues():
            kwargs[k] = conversion.py2ro(v)
        fun = self._extractfunction
        args.insert(0, self._parent)
        res = fun(*args, **kwargs)
        res = conversion.py2ro(res)
        return res
Exemplo n.º 3
0
 def from_csvfile(path, header = True, sep = ",",
                  quote = "\"", dec = ".", 
                  row_names = rinterface.MissingArg,
                  col_names = rinterface.MissingArg,
                  fill = True, comment_char = "",
                  as_is = False):
     """ Create an instance from data in a .csv file. """
     path = conversion.py2ro(path)
     header = conversion.py2ro(header)
     sep = conversion.py2ro(sep)
     quote = conversion.py2ro(quote)
     dec = conversion.py2ro(dec)
     if row_names is not rinterface.MissingArg:
         row_names = conversion.py2ro(row_names)
     if col_names is not rinterface.MissingArg:
         col_names = conversion.py2ro(col_names)
     fill = conversion.py2ro(fill)
     comment_char = conversion.py2ro(comment_char)
     as_is = conversion.py2ro(as_is)
     res = DataFrame._read_csv(path, 
                               **{'header': header, 'sep': sep,
                                  'quote': quote, 'dec': dec,
                                  'row.names': row_names,
                                  'col.names': col_names,
                                  'fill': fill,
                                  'comment.char': comment_char,
                                  'as.is': as_is})
     res = conversion.ri2py(res)
     return res
Exemplo n.º 4
0
 def from_csvfile(path, header = True, sep = ",",
                  quote = "\"", dec = ".", 
                  row_names = rinterface.MissingArg,
                  col_names = rinterface.MissingArg,
                  fill = True, comment_char = "",
                  as_is = False):
     """ Create an instance from data in a .csv file. """
     path = conversion.py2ro(path)
     header = conversion.py2ro(header)
     sep = conversion.py2ro(sep)
     quote = conversion.py2ro(quote)
     dec = conversion.py2ro(dec)
     if row_names is not rinterface.MissingArg:
         row_names = conversion.py2ro(row_names)
     if col_names is not rinterface.MissingArg:
         col_names = conversion.py2ro(col_names)
     fill = conversion.py2ro(fill)
     comment_char = conversion.py2ro(comment_char)
     as_is = conversion.py2ro(as_is)
     res = DataFrame._read_csv(path, 
                               **{'header': header, 'sep': sep,
                                  'quote': quote, 'dec': dec,
                                  'row.names': row_names,
                                  'col.names': col_names,
                                  'fill': fill,
                                  'comment.char': comment_char,
                                  'as.is': as_is})
     res = conversion.ri2py(res)
     return res
Exemplo n.º 5
0
 def __getitem__(self, item):
     fun = self._extractfunction
     args = rlc.TaggedList(item)
     for i, (k, v) in enumerate(args.iteritems()):
         args[i] = conversion.py2ro(v)
     args.insert(0, self._parent)
     res = fun.rcall(args.items(), globalenv_ri)
     res = conversion.py2ro(res)
     return res
Exemplo n.º 6
0
 def __getitem__(self, item):
     fun = self._extractfunction
     args = rlc.TaggedList(item)
     for i, (k, v) in enumerate(args.iteritems()):
         args[i] = conversion.py2ro(v)
     args.insert(0, self._parent)
     res = fun.rcall(args.items(),
                     globalenv_ri)
     res = conversion.py2ro(res)
     return res
Exemplo n.º 7
0
    def to_csvfile(self, path, quote = True, sep = ",", eol = os.linesep, na = "NA", dec = ".", 
                   row_names = True, col_names = True, qmethod = "escape", append = False):
        """ Save the data into a .csv file. 

        path         : string with a path 
        quote        : quote character
        sep          : separator character
        eol          : end-of-line character(s)
        na           : string for missing values
        dec          : string for decimal separator
        row_names    : boolean (save row names, or not)
        col_names    : boolean (save column names, or not)
        comment_char : method to 'escape' special characters
        append       : boolean (append if the file in the path is already existing, or not)
        """
        path = conversion.py2ro(path)
        append = conversion.py2ro(append)
        sep = conversion.py2ro(sep)
        eol = conversion.py2ro(eol)
        na = conversion.py2ro(na)
        dec = conversion.py2ro(dec)
        row_names = conversion.py2ro(row_names)
        col_names = conversion.py2ro(col_names)
        qmethod = conversion.py2ro(qmethod)
        res = self._write_table(self, **{'file': path, 'quote': quote, 'sep': sep, 
                                         'eol': eol, 'na': na, 'dec': dec,
                                         'row.names': row_names, 
                                         'col.names': col_names, 'qmethod': qmethod, 'append': append})
        return res
Exemplo n.º 8
0
 def to_csvfile(self,
                path,
                quote=True,
                sep=",",
                eol=os.linesep,
                na="NA",
                dec=".",
                row_names=True,
                col_names=True,
                qmethod="escape",
                append=False):
     """ Save the data into a .csv file. """
     path = conversion.py2ro(path)
     append = conversion.py2ro(append)
     sep = conversion.py2ro(sep)
     eol = conversion.py2ro(eol)
     na = conversion.py2ro(na)
     dec = conversion.py2ro(dec)
     row_names = conversion.py2ro(row_names)
     col_names = conversion.py2ro(col_names)
     qmethod = conversion.py2ro(qmethod)
     res = self._write_table(
         self, **{
             'file': path,
             'quote': quote,
             'sep': sep,
             'eol': eol,
             'na': na,
             'dec': dec,
             'row.names': row_names,
             'col.names': col_names,
             'qmethod': qmethod,
             'append': append
         })
     return res
Exemplo n.º 9
0
    def to_csvfile(self, path, quote = True, sep = ",", eol = os.linesep, na = "NA", dec = ".", 
                   row_names = True, col_names = True, qmethod = "escape", append = False):
        """ Save the data into a .csv file. 

        path         : string with a path 
        quote        : quote character
        sep          : separator character
        eol          : end-of-line character(s)
        na           : string for missing values
        dec          : string for decimal separator
        row_names    : boolean (save row names, or not)
        col_names    : boolean (save column names, or not)
        comment_char : method to 'escape' special characters
        append       : boolean (append if the file in the path is already existing, or not)
        """
        path = conversion.py2ro(path)
        append = conversion.py2ro(append)
        sep = conversion.py2ro(sep)
        eol = conversion.py2ro(eol)
        na = conversion.py2ro(na)
        dec = conversion.py2ro(dec)
        row_names = conversion.py2ro(row_names)
        col_names = conversion.py2ro(col_names)
        qmethod = conversion.py2ro(qmethod)
        res = self._write_table(self, **{'file': path, 'quote': quote, 'sep': sep, 
                                         'eol': eol, 'na': na, 'dec': dec,
                                         'row.names': row_names, 
                                         'col.names': col_names, 'qmethod': qmethod, 'append': append})
        return res
Exemplo n.º 10
0
 def __setitem__(self, item, value):
     """ Assign a given value to a given index position in the vector """
     args = rlc.TaggedList.from_iteritems(item)
     for i, (k, v) in enumerate(args.iteritems()):
         args[i] = conversion.py2ro(v)
     args.append(conversion.py2ro(value), tag=None)
     args.insert(0, self._parent, tag=None)
     fun = self._replacefunction
     res = fun.rcall(tuple(args.iteritems()), globalenv_ri)
     #FIXME: check refcount and copying
     self._parent.__sexp__ = res.__sexp__
Exemplo n.º 11
0
 def __setitem__(self, item, value):
     """ Assign a given value to a given index position in the vector """
     args = rlc.TaggedList.from_iteritems(item)
     for i, (k, v) in enumerate(args.iteritems()):
         args[i] = conversion.py2ro(v)
     args.append(conversion.py2ro(value), tag = None)
     args.insert(0, self._parent, tag = None)
     fun = self._replacefunction
     res = fun.rcall(tuple(args.iteritems()),
                     globalenv_ri)
     #FIXME: check refcount and copying
     self._parent.__sexp__ = res.__sexp__
Exemplo n.º 12
0
    def from_csvfile(path,
                     header=True,
                     sep=",",
                     quote="\"",
                     dec=".",
                     row_names=rinterface.MissingArg,
                     col_names=rinterface.MissingArg,
                     fill=True,
                     comment_char="",
                     as_is=False):
        """ Create an instance from data in a .csv file. 

        path         : string with a path 
        header       : boolean (heading line with column names or not)
        sep          : separator character
        quote        : quote character
        row_names    : column name, or column index for column names (warning: indexing starts at one in R)
        fill         : boolean (fill the lines when less entries than columns)
        comment_char : comment character
        as_is        : boolean (keep the columns of strings as such, or turn them into factors) 
        """
        path = conversion.py2ro(path)
        header = conversion.py2ro(header)
        sep = conversion.py2ro(sep)
        quote = conversion.py2ro(quote)
        dec = conversion.py2ro(dec)
        if row_names is not rinterface.MissingArg:
            row_names = conversion.py2ro(row_names)
        if col_names is not rinterface.MissingArg:
            col_names = conversion.py2ro(col_names)
        fill = conversion.py2ro(fill)
        comment_char = conversion.py2ro(comment_char)
        as_is = conversion.py2ro(as_is)
        res = DataFrame._read_csv(
            path, **{
                'header': header,
                'sep': sep,
                'quote': quote,
                'dec': dec,
                'row.names': row_names,
                'col.names': col_names,
                'fill': fill,
                'comment.char': comment_char,
                'as.is': as_is
            })
        res = conversion.ri2py(res)
        return res
Exemplo n.º 13
0
 def to_csvfile(self, path, quote = True, sep = ",", eol = os.linesep, na = "NA", dec = ".", 
                row_names = True, col_names = True, qmethod = "escape", append = False):
     """ Save the data into a .csv file. """
     path = conversion.py2ro(path)
     append = conversion.py2ro(append)
     sep = conversion.py2ro(sep)
     eol = conversion.py2ro(eol)
     na = conversion.py2ro(na)
     dec = conversion.py2ro(dec)
     row_names = conversion.py2ro(row_names)
     col_names = conversion.py2ro(col_names)
     qmethod = conversion.py2ro(qmethod)
     res = self._write_table(self, **{'file': path, 'quote': quote, 'sep': sep, 
                                      'eol': eol, 'na': na, 'dec': dec,
                                      'row.names': row_names, 
                                      'col.names': col_names, 'qmethod': qmethod, 'append': append})
     return res
Exemplo n.º 14
0
 def __setitem__(self, item, value):
     """ Assign a given value to a given index position in the vector.
     The index position can either be:
     - an int: x[1] = y
     - a tuple of ints: x[1, 2, 3] = y
     - an iteritem-able object (such as a dict): x[{'i': 1}] = y
     """
     fun = self._replacefunction
     if type(item) is tuple:
         args = list([
             None,
         ] * (len(item) + 2))
         for i, v in enumerate(item):
             args[i + 1] = conversion.py2ro(v)
         args[-1] = conversion.py2ro(value)
         args[0] = self._parent
         res = fun(*args)
     elif (type(item) is dict) or (type(item) is rlc.TaggedList):
         args = rlc.TaggedList.from_iteritems(item)
         for i, (k, v) in enumerate(args.iteritems()):
             args[i] = conversion.py2ro(v)
         args.append(conversion.py2ro(value), tag=None)
         args.insert(0, self._parent, tag=None)
         res = fun.rcall(tuple(args.iteritems()), globalenv_ri)
     else:
         args = [
             self._parent,
             conversion.py2ro(item),
             conversion.py2ro(value)
         ]
         res = fun(*args)
     #FIXME: check refcount and copying
     self._parent.__sexp__ = res.__sexp__
Exemplo n.º 15
0
 def __setitem__(self, item, value):
     """ Assign a given value to a given index position in the vector.
     The index position can either be:
     - an int: x[1] = y
     - a tuple of ints: x[1, 2, 3] = y
     - an iteritem-able object (such as a dict): x[{'i': 1}] = y
     """
     fun = self._replacefunction
     if type(item) is tuple:
         args = list([None, ] * (len(item)+2))
         for i, v in enumerate(item):
             args[i+1] = conversion.py2ro(v)
         args[-1] = conversion.py2ro(value)
         args[0] = self._parent
         res = fun(*args)
     elif (type(item) is dict) or (type(item) is rlc.TaggedList):
         args = rlc.TaggedList.from_iteritems(item)
         for i, (k, v) in enumerate(args.iteritems()):
             args[i] = conversion.py2ro(v)
         args.append(conversion.py2ro(value), tag = None)
         args.insert(0, self._parent, tag = None)
         res = fun.rcall(tuple(args.iteritems()),
                         globalenv_ri)
     else:
         args = [self._parent,
                 conversion.py2ro(item),
                 conversion.py2ro(value)]
         res = fun(*args)
     #FIXME: check refcount and copying
     self._parent.__sexp__ = res.__sexp__
Exemplo n.º 16
0
    def from_csvfile(path, header = True, sep = ",",
                     quote = "\"", dec = ".", 
                     row_names = rinterface.MissingArg,
                     col_names = rinterface.MissingArg,
                     fill = True, comment_char = "",
                     as_is = False):
        """ Create an instance from data in a .csv file. 

        path         : string with a path 
        header       : boolean (heading line with column names or not)
        sep          : separator character
        quote        : quote character
        row_names    : column name, or column index for column names (warning: indexing starts at one in R)
        fill         : boolean (fill the lines when less entries than columns)
        comment_char : comment character
        as_is        : boolean (keep the columns of strings as such, or turn them into factors) 
        """
        path = conversion.py2ro(path)
        header = conversion.py2ro(header)
        sep = conversion.py2ro(sep)
        quote = conversion.py2ro(quote)
        dec = conversion.py2ro(dec)
        if row_names is not rinterface.MissingArg:
            row_names = conversion.py2ro(row_names)
        if col_names is not rinterface.MissingArg:
            col_names = conversion.py2ro(col_names)
        fill = conversion.py2ro(fill)
        comment_char = conversion.py2ro(comment_char)
        as_is = conversion.py2ro(as_is)
        res = DataFrame._read_csv(path, 
                                  **{'header': header, 'sep': sep,
                                     'quote': quote, 'dec': dec,
                                     'row.names': row_names,
                                     'col.names': col_names,
                                     'fill': fill,
                                     'comment.char': comment_char,
                                     'as.is': as_is})
        res = conversion.ri2py(res)
        return res
Exemplo n.º 17
0
 def __dim_set(self, value):
     value = conversion.py2ro(value)
     res = self._dim_set(self, value)
         #FIXME: not properly done
     raise(Exception("Not yet implemented"))
Exemplo n.º 18
0
 def __dim_set(self, value):
     value = conversion.py2ro(value)
     res = self._dim_set(self, value)
     #FIXME: not properly done
     raise (Exception("Not yet implemented"))
Exemplo n.º 19
0
 def __levels_set(self, value):
     res = self._levels_set(self, conversion.py2ro(value))
     self.__sexp__ = res.__sexp__
Exemplo n.º 20
0
 def _names_set(self, value):
     res = globalenv_ri.get("names<-")(self, conversion.py2ro(value))
     self.__sexp__ = res.__sexp__
Exemplo n.º 21
0
 def _names_set(self, value):
     res = globalenv_ri.get("names<-")(self, conversion.py2ro(value))
     self.__sexp__ = res.__sexp__
Exemplo n.º 22
0
 def __setitem__(self, item, value):
     robj = conversion.py2ro(value)
     super(Environment, self).__setitem__(item, robj)
Exemplo n.º 23
0
 def __levels_set(self, value):
     res = self._levels_set(self, conversion.py2ro(value))
     self.__sexp__ = res.__sexp__