Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

Python Programming/Extending with R

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

Extending with Perl Links It is possible to call R functions and even modules direcly from Python. One easy way to do this is the rpy2 interface. In the following code snippet, an R module called preprocessCore from the bioconductor portal is loaded and the quantile normalization function is applied on a matrix that is created in python and then converted back to python again. import rpy2.robjects as robjects from rpy2.robjects.packages import importr import numpy preprocessCore = importr('preprocessCore') matrix = [ [1,2,3,4,5], [1,3,5,7,9], [2,4,6,8,10] ] v = robjects.FloatVector([ element for col in matrix for element in col ]) m = robjects.r['matrix'](v, ncol = len(matrix), byrow=False) Rnormalized_matrix = preprocessCore.normalize_quantiles(m) normalized_matrix = numpy.array( Rnormalized_matrix) It is thus possible to handle R modules and objects. See also http://wiki.python.org/moin/IntegratingPythonWithOtherLanguages#R http://rpy.sourceforge.net/rpy2.html Extending with Perl Links