Beispiel #1
0
    def sync_with_r(self):
        '''Query the rsession for all objects and try to recreate using the rsession wrapper objects'''
        for obj in rsession.r.ls():
            #try:
                pyobj = rsession.ro.globalEnv.get(str(obj))
                typeof = rsession.r['class'](pyobj)[0]
                #There are also multivariable time series (is_mts) that we should worry about
                #Converting arrays to dataframes flattens the array
                if typeof == 'table':
                    info('FYI, the array object you selected is being imported as a flattened dataframe.')
                    pyobj = rsession.df(pyobj)

                if typeof == 'ts':
                    #Strip all the data needed to recreate the object
                    start = rsession.r['start'](pyobj)
                    end = rsession.r['end'](pyobj)
                    frequency = rsession.r['frequency'](pyobj)
                    times = rsession.r['time'](pyobj)
                    deltat = rsession.r['deltat'](pyobj)
                    data = numpy.array(pyobj).T
                    label = str(obj)
                    self.render_timeseries(data,label=label,start=start,end=end,frequency=frequency,deltat=deltat)

                if typeof == 'data.frame':
                    data = numpy.array(pyobj).T
                    rownames=pyobj.rownames()
                    columns = odict()
                    for col,dat in zip(pyobj.colnames(),pyobj):
                        ptype = rsession.typeof(dat)
                        columns[col] = rsession.translate_types(ptype)
                    self.render_dataframe(data,columns,name=str(obj),rownames=rownames)

                if typeof == 'htest':
                    self.render_description(pyobj,str(obj))

                if typeof == 'lm':
                    self.render_linear_model(pyobj,'Linear Model')

                if typeof == 'nls':
                    self.render_linear_model(pyobj,'Nonlinear Model')

                #Vectors
                if typeof == 'numeric':
                    #Cast into dataframe
                    pyobj = rsession.df(pyobj)
                    data = numpy.array(pyobj).T
                    rownames=pyobj.rownames()
                    columns = odict()
                    for col,dat in zip(pyobj.colnames(),pyobj):
                        ptype = rsession.typeof(dat)
                        columns[col] = rsession.translate_types(ptype)
                    self.render_dataframe(data,columns,name=str(obj),rownames=rownames)
                if config.__devel__:
                    print('Tring to import to workspace. \n'+str(type(pyobj)) + '\n')
Beispiel #2
0
    def set_columns(self,list_of_vars,types=None):
        self.dimensions[1] = len(list_of_vars)
        self.columns = list_of_vars

        for i,title in enumerate(list_of_vars):
            if types:
                #col = gtk.TreeViewColumn(title + '\n'+ str(translate_types(types[i],reverse=True))+'')
                col = gtk.TreeViewColumn(title + '\n'+ str(translate_types(types[i],reverse=True))+'')
            else:
                #We have to do this so the rownames line up
                col = gtk.TreeViewColumn(title + '\n')
            col.set_property('clickable', True)
            col.set_flags(gtk.CAN_FOCUS)

            self.view.append_column(col)

            cell = gtk.CellRendererText()
            cell.set_property('font-desc', pango.FontDescription('sans 8'))

            if self.editable:
                cell.set_property('editable', True)
                handler = cell.connect('edited', self.edited, (self.store, i))
                self.connections.append((cell,handler))

            col.pack_start(cell)
            col.add_attribute(cell,'text',i)
Beispiel #3
0
    def render_timeseries(self,data,label=None,start=None,end=None,frequency=None,deltat=None,times=None):
        '''Time series are handled just like dataframes except we allow for options on frequency/start/end'''

        #This only works for ts, not mts at the moment
        ptype = rsession.typeof(data[0])
        columns = {'V1':rsession.translate_types(ptype)}

        if not label:
            inc = 0
            for unmes in self.robjects.keys():
                if 'unnamed' in unmes:
                    inc += 1
            name = 'unnamed' + str(inc+1)

        timeseries = rsession.timeseries(data,label=label,start=start,end=end,frequency=frequency,deltat=deltat)
        rownames = timeseries.rownames

        self.add_r_object(timeseries,label)
        self.set_active_robject(timeseries)
        self.handle_dataview(data,columns,rownames=rownames,editable=True)