当前位置: 首页>>代码示例>>Python>>正文


Python rpy2.robjects方法代码示例

本文整理汇总了Python中rpy2.robjects方法的典型用法代码示例。如果您正苦于以下问题:Python rpy2.robjects方法的具体用法?Python rpy2.robjects怎么用?Python rpy2.robjects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rpy2的用法示例。


在下文中一共展示了rpy2.robjects方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _transform_options

# 需要导入模块: import rpy2 [as 别名]
# 或者: from rpy2 import robjects [as 别名]
def _transform_options(styler_r, options):
        transformed_options = copy.deepcopy(options)

        if "math_token_spacing" in transformed_options:
            if isinstance(options["math_token_spacing"], dict):
                transformed_options["math_token_spacing"] = rpy2.robjects.ListVector(
                    options["math_token_spacing"]
                )
            else:
                transformed_options["math_token_spacing"] = rpy2.robjects.ListVector(
                    getattr(styler_r, options["math_token_spacing"])()
                )

        if "reindention" in transformed_options:
            if isinstance(options["reindention"], dict):
                transformed_options["reindention"] = rpy2.robjects.ListVector(
                    options["reindention"]
                )
            else:
                transformed_options["reindention"] = rpy2.robjects.ListVector(
                    getattr(styler_r, options["reindention"])()
                )
        return transformed_options 
开发者ID:ryantam626,项目名称:jupyterlab_code_formatter,代码行数:25,代码来源:formatters.py

示例2: updateKnownVignettes

# 需要导入模块: import rpy2 [as 别名]
# 或者: from rpy2 import robjects [as 别名]
def updateKnownVignettes(self):
        self._table.clear()

        vignettes = robjects.r["vignette"]().subset("results")[0]

        nrows = robjects.baseenv["nrow"](vignettes)[0]
        ncols = robjects.baseenv["ncol"](vignettes)[0]
        for i in range(1, nrows + 1):
            row = []
            pack = vignettes.subset(i, 1)[0]
            row.append(pack)
            pack = vignettes.subset(i, 3)[0]
            row.append(pack)
            pack = vignettes.subset(i, 4)[0]
            row.append(pack)
            self._table.append(row)
        
        self._vignettes = vignettes 
开发者ID:rpy2,项目名称:rpy2,代码行数:20,代码来源:radmin.py

示例3: viewAction

# 需要导入模块: import rpy2 [as 别名]
# 或者: from rpy2 import robjects [as 别名]
def viewAction(self, widget, data=None):
        # Get the selection in the gtk.TreeView
	selection = self._treeView.get_selection()
	# Get the selection iter
	model, selection_iter = selection.get_selected()
        if selection_iter:
            packName = self._table.get_value(selection_iter, 
                                             self.PACKAGE_I)
            vigName = self._table.get_value(selection_iter, 
                                            self.ITEM_I)
            
            pdffile = robjects.r.vignette(vigName, package = packName)
            pdffile = pdffile.subset("file")[0][0]
            pdfviewer = robjects.baseenv["options"]("pdfviewer")[0][0]

            pid = os.spawnl(os.P_NOWAIT, pdfviewer, pdffile) 
开发者ID:rpy2,项目名称:rpy2,代码行数:18,代码来源:radmin.py

示例4: updateRelevantHelp

# 需要导入模块: import rpy2 [as 别名]
# 或者: from rpy2 import robjects [as 别名]
def updateRelevantHelp(self, string):
        self._table.clear()
        if string is None:
            return
        agrep = [False, True][self._fuzzyButton.get_active()]
        matches = robjects.r["help.search"](string, agrep=agrep).subset("matches")[0]
        #import pdb; pdb.set_trace()
        nrows = robjects.r.nrow(matches)[0]
        ncols = robjects.r.ncol(matches)[0]
        for i in range(1, nrows + 1):
            row = []
            pack = matches.subset(i, 1)[0]
            row.append(pack)
            pack = matches.subset(i, 2)[0]
            row.append(pack)
            pack = matches.subset(i, 3)[0]
            row.append(pack)
            self._table.append(row) 
开发者ID:rpy2,项目名称:rpy2,代码行数:20,代码来源:radmin.py

示例5: evaluateAction

# 需要导入模块: import rpy2 [as 别名]
# 或者: from rpy2 import robjects [as 别名]
def evaluateAction(self, widget, data=None):
        buffer = self._buffer
        start_iter = buffer.get_iter_at_mark(self._start_mark)

        stop_iter = buffer.get_iter_at_offset(buffer.get_char_count())
        rcode = buffer.get_text(start_iter, stop_iter)

        rbuf = []
        def f(x):
            rbuf.append(x)

        robjects.rinterface.setWriteConsole(f)

        if rcode.strip() == '':
            res = None
        else:
            try:            
                res = robjects.r('withVisible( ' + rcode + ' )')
                visible = res.rx2("visible")[0]
                if visible:
                    res = res.rx2("value")
                else:
                    res = None
            except robjects.rinterface.RRuntimeError, rre:
                res = str(rre) 
开发者ID:rpy2,项目名称:rpy2,代码行数:27,代码来源:radmin.py

示例6: importable

# 需要导入模块: import rpy2 [as 别名]
# 或者: from rpy2 import robjects [as 别名]
def importable(self) -> bool:
        try:
            import rpy2.robjects.packages as rpackages

            rpackages.importr(self.package_name, robject_translations={".env": "env"})

            return True
        except Exception:
            return False 
开发者ID:ryantam626,项目名称:jupyterlab_code_formatter,代码行数:11,代码来源:formatters.py

示例7: format_code

# 需要导入模块: import rpy2 [as 别名]
# 或者: from rpy2 import robjects [as 别名]
def format_code(self, code: str, notebook: bool, **options) -> str:
        import rpy2.robjects.packages as rpackages

        format_r = rpackages.importr(
            self.package_name, robject_translations={".env": "env"}
        )
        formatted_code = format_r.tidy_source(text=code, output=False, **options)
        return "\n".join(formatted_code[0]) 
开发者ID:ryantam626,项目名称:jupyterlab_code_formatter,代码行数:10,代码来源:formatters.py

示例8: updateInstalledLibraries

# 需要导入模块: import rpy2 [as 别名]
# 或者: from rpy2 import robjects [as 别名]
def updateInstalledLibraries(self):
        self._table.clear()
        installedLibraries = robjects.r["installed.packages"]()
        nrows = robjects.r.nrow(installedLibraries)[0]
        ncols = robjects.r.ncol(installedLibraries)[0]
        for i in range(1, nrows + 1):
            row = []
            pack = installedLibraries.subset(i, 1)[0]
            row.append(pack)
            pack = installedLibraries.subset(i, 3)[0]
            row.append(pack)
            pack = installedLibraries.subset(i, 4)[0]
            row.append(pack)
            self._table.append(row) 
开发者ID:rpy2,项目名称:rpy2,代码行数:16,代码来源:radmin.py

示例9: searchAction

# 需要导入模块: import rpy2 [as 别名]
# 或者: from rpy2 import robjects [as 别名]
def searchAction(self, widget, data=None):
        string = (self.sentry.get_text())
        self.updateInstalledLibraries()
        if string is None:
            return
        matches = robjects.r["help.search"](string).subset("matches")[0]
        spacks = [x for x in matches.subset(True, "Package")]
        spacks = set(spacks)
        toremove = []
        for ii, row in enumerate(self._table):
            if not (row[0] in spacks):
                toremove.append(ii)
        toremove.reverse()
        for r in toremove:
            self._table.remove(self._table.get_iter(r)) 
开发者ID:rpy2,项目名称:rpy2,代码行数:17,代码来源:radmin.py

示例10: loadAction

# 需要导入模块: import rpy2 [as 别名]
# 或者: from rpy2 import robjects [as 别名]
def loadAction(self, widget, data=None):
        # Get the selection in the gtk.TreeView
	selection = self._treeView.get_selection()
	# Get the selection iter
	model, selection_iter = selection.get_selected()
        if selection_iter:
            packName = self._table.get_value(selection_iter, 
                                            self.PACKAGE_I)
            self._console.append('library("%s")\n' %packName)

            if sys.platform == 'win32':
                tfile = robjects.baseenv["tempfile"]()
                tmp = robjects.baseenv["file"](tfile, open="w")
            else:
                tmp = robjects.baseenv["fifo"]("")
            robjects.baseenv["sink"](tmp)
            
            robjects.baseenv["library"](packName)

            if sys.platform == 'win32':
                robjects.baseenv["close"](tmp)
                tmp = robjects.baseenv["file"](tfile, open="r")
            out = robjects.baseenv["readLines"](tmp)
            for line in out:
                self._console.append(str(line)+"\n")
            robjects.r.close(tmp)
            self._console.append("> ") 
开发者ID:rpy2,项目名称:rpy2,代码行数:29,代码来源:radmin.py

示例11: buttonAction

# 需要导入模块: import rpy2 [as 别名]
# 或者: from rpy2 import robjects [as 别名]
def buttonAction(self, widget, data=None):
         treeselection = self._treeView.get_selection()
         (model, rowiter) = treeselection.get_selected()
         if rowiter is None:
             return
         #import pdb; pdb.set_trace()
         row = self._table[rowiter]
         helpFile = robjects.r.help(row[0], package=row[2]) 
开发者ID:rpy2,项目名称:rpy2,代码行数:10,代码来源:radmin.py

示例12: updateTable

# 需要导入模块: import rpy2 [as 别名]
# 或者: from rpy2 import robjects [as 别名]
def updateTable(self, string):
        self._table.clear()
        
        for symbol in self._env: 
            stype = robjects.baseenv["class"](self._env[symbol])
            row = [symbol, stype]
            self._table.append(row)

        if string is None:
            return 
开发者ID:rpy2,项目名称:rpy2,代码行数:12,代码来源:radmin.py

示例13: gobject_process_revents

# 需要导入模块: import rpy2 [as 别名]
# 或者: from rpy2 import robjects [as 别名]
def gobject_process_revents():
    robjects.rinterface.process_revents()
    return True 
开发者ID:rpy2,项目名称:rpy2,代码行数:5,代码来源:radmin.py

示例14: calculate_survival_stats

# 需要导入模块: import rpy2 [as 别名]
# 或者: from rpy2 import robjects [as 别名]
def calculate_survival_stats(times, events, values_by_record):
    """
    @param times: time elapsed before the event occurs, or when subject is censored
    @param events: 1 indicates event was observed; 0 indicates event did not occur
    @param values_by_record: two dimensional double array.  Each row is the predictor values for a record (ex: gene)
    @return: array where each element contains the hazard ratio and pvalue for the record
    """
    # flatten values of two dimensional array for use by R
    # in R, matrices are simply an array where you specify number of columns per row
    flattened_values = [y for row in values_by_record for y in row]

    t = robjects.FloatVector(times)
    e = robjects.IntVector(events)
    v = robjects.FloatVector(flattened_values)

    # convert flattened values into an R matrix
    m = robjects.r['matrix'](v, nrow=len(values_by_record), byrow=True)

    #load R library
    r('library(survival)')

    # assign variables in R
    r.assign('valuesMatrix', m)
    r.assign('numSamples', len(times))
    r.assign('times', t)
    r.assign('events', e)

    # calculate statistics by applying coxph to each record's values
    logging.debug('Calculating stats')
    r("""res <- apply(valuesMatrix,1, function(values) {
      coxlist = try(coxph(Surv(times,events)~values + cluster(1:numSamples[1])))
      return(c(summary(coxlist)$coefficients[2], summary(coxlist)$coefficients[6]))
      })""")
    logging.debug('Done calculating stats')

    # convert results
    r_res = robjects.r['res']
    res_iter = iter(r_res)
    results = []
    for hazard in res_iter:
        pval = next(res_iter)
        results.append({'hazard': hazard, 'pval': pval})
    return results 
开发者ID:station-x,项目名称:lambda-r-survival-stats,代码行数:45,代码来源:handler.py


注:本文中的rpy2.robjects方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。