Revision: 571 http://rpy.svn.sourceforge.net/rpy/?rev=571&view=rev Author: lgautier Date: 2008-07-05 07:43:41 -0700 (Sat, 05 Jul 2008)
Log Message: ----------- doc: - many fixes and little additions - transferred content of preface.rst to the index / main page. Modified Paths: -------------- branches/rpy_nextgen/doc/source/index.rst branches/rpy_nextgen/doc/source/overview.rst branches/rpy_nextgen/doc/source/rinterface.rst branches/rpy_nextgen/doc/source/robjects.rst Removed Paths: ------------- branches/rpy_nextgen/doc/source/preface.rst Modified: branches/rpy_nextgen/doc/source/index.rst =================================================================== --- branches/rpy_nextgen/doc/source/index.rst 2008-07-04 13:59:57 UTC (rev 570) +++ branches/rpy_nextgen/doc/source/index.rst 2008-07-05 14:43:41 UTC (rev 571) @@ -5,12 +5,23 @@ Documentation for rpy2 ====================== + +This document describes RPy2, a rewrite of +the RPy package. + +It is developped for R-2.7 (and is not expected to work +with a previous version), together with Python 2.5. Compatibility +with Python 2.4 is expected but it was observed to segfault at rare occasions +(and the cause is not yet identified). + + + + Contents: .. toctree:: :maxdepth: 2 - preface overview robjects rinterface Modified: branches/rpy_nextgen/doc/source/overview.rst =================================================================== --- branches/rpy_nextgen/doc/source/overview.rst 2008-07-04 13:59:57 UTC (rev 570) +++ branches/rpy_nextgen/doc/source/overview.rst 2008-07-05 14:43:41 UTC (rev 571) @@ -45,9 +45,8 @@ ^^^^^^^^ Source Python packages, as well as pre-compiled binaries for Microsoft's Windows are available -on the Sourceforge page. +on the `Sourceforge page <http://downloads.sourceforge.net/rpy>`_. - .. note:: MacOSX binaries may appear in the future (contributions to build them are welcome) @@ -119,3 +118,15 @@ demonstrate how to extend :mod:`rpy2.rinterface` with an alternative to inheritance. + +Acknowledgements +---------------- + +Acknowledgements go to: + +Walter Moreira, and Gregory Warnes + For the original RPy and its maintainance through the years. + +Alexander Belopolsky. + His code contribution to RPy is acknowledged. I have found great + inspiration in reading that code. Deleted: branches/rpy_nextgen/doc/source/preface.rst =================================================================== --- branches/rpy_nextgen/doc/source/preface.rst 2008-07-04 13:59:57 UTC (rev 570) +++ branches/rpy_nextgen/doc/source/preface.rst 2008-07-05 14:43:41 UTC (rev 571) @@ -1,20 +0,0 @@ -Preface -======= - -This presentation describes RPy2, a rewrite of -the RPy package. - -It is developped for R-2.7 (and is not expected to work -with a previous version), together with Python 2.5. Compatibility -with Python 2.4 is expected but not tested when writing -those lines. - -Acknowledgements go to: - -Walter Moreira, and Gregory Warnes - For the original RPy and its maintainance through the years. - -Alexander Belopolsky. - The contributed code of Alexander Belopolsky, who contributed - a first rewrite to RPy is acknowledged. I have found great - inspiration in reading that code. Modified: branches/rpy_nextgen/doc/source/rinterface.rst =================================================================== --- branches/rpy_nextgen/doc/source/rinterface.rst 2008-07-04 13:59:57 UTC (rev 570) +++ branches/rpy_nextgen/doc/source/rinterface.rst 2008-07-05 14:43:41 UTC (rev 571) @@ -32,9 +32,9 @@ >>> rinterface.initEmbeddedR() -Initialization should only be performed once and in the case -of a second call to :func:`initEmbeddedR`, to avoid unpredictable results -when using the embedded R, an exception is be fired. +Initialization should only be performed once. In the unfortunate event +of a second call to :func:`initEmbeddedR`, and to avoid unpredictable results +when using the embedded R, an exception will be fired. Parameters for the initialization are in the module variable `initOptions`. @@ -254,6 +254,7 @@ The functions *array* and *asarray* is all that is needed: + >>> import numpy >>> rx = rinterface.SexpVector([1,2,3,4], rinterface.INTSXP) >>> nx = numpy.array(rx) @@ -263,6 +264,8 @@ .. note:: when using :meth:`asarray`, the data are not copied. +>>> rx[2] +3 >>> nx_nc[2] = 42 >>> rx[2] 42 Modified: branches/rpy_nextgen/doc/source/robjects.rst =================================================================== --- branches/rpy_nextgen/doc/source/robjects.rst 2008-07-04 13:59:57 UTC (rev 570) +++ branches/rpy_nextgen/doc/source/robjects.rst 2008-07-05 14:43:41 UTC (rev 571) @@ -83,7 +83,7 @@ The astute reader will quickly realize that R objects named by python variables can -be plugged into code by their string representation: +be plugged into code through their string representation: >>> x = robjects.r.rnorm(100) >>> robjects.r('hist(%s, xlab="x", main="hist(x)")' %repr(x)) @@ -155,7 +155,7 @@ >>> x.r[1] 1L -The two next examples demonstrate features of `R` regarding indexing, +The two next examples demonstrate some of `R`'s features regarding indexing, respectively element exclusion and recycling rule: >>> x.r[-1] @@ -174,7 +174,7 @@ are performed element-wise in R, recycling the shortest vector if, and as much as, necessary. -The delegating attribute mention in the Indexing section can also +The delegating attribute mentioned in the Indexing section can also be used with the following operators: +----------+---------+ @@ -232,6 +232,14 @@ A :class:`RMatrix` is a special case of :class:`RArray`. +:class:`RDataFrame` +------------------- + +A :class:`RDataFrame` represents the `R` class `data.frame'. + +Currently, the constructor is flagged as experimental. It accepts either a :class:`rinterface.SexpVector` +or a dictonnary which elements will be the columns of the `data.frame`. + R environments ============== @@ -350,29 +358,54 @@ Mapping between rpy2 objects and other python objects ===================================================== -The conversion, as often needed with RPy-1.x, is no longer +The conversion, often present when working with RPy-1.x, is no longer necessary as the R objects can be either passed on to R functions -or used in Python. T +or used in Python. -There is a low-level mapping between `R` and `Python` objects -performed behind the (Python-level) scene. +However, there is a low-level mapping between `R` and `Python` objects +performed behind the (Python-level) scene, done by the :mod:`rpy2.rinterface`, +while an higher-level mapping is done between low-level objects and +higher-level objects using the functions: -The mapping between low-level objects and higher-level objects -is performed by the functions. - :meth:`ri2py` - :mod:`rpy2.rinterface` to Python + :mod:`rpy2.rinterface` to Python. By default, this function + is just an alias for the function :meth:`default_ri2py`. :meth:`py2ri` - Python to :mod:`rpy2.rinterface` + Python to :mod:`rpy2.rinterface`. By default, this function + is just an alias for the function :meth:`default_py2ri`. :meth:`py2ro` Python to :mod:`rpy2.robjects`. That one function - is merely a call to py2ri followed by a call to ri2py. + is merely a call to :meth:`py2ri` followed by a call to :meth:`ri2py`. -Those functions can be modifyied to satisfy all requirements. +Those functions can be modifyied to satisfy all requirements, with +the easiest option being to write a custom function calling itself +the default function. +As an example, let's assume that one want to return atomic values +whenever an R numerical vector is of length one. This is only a matter +of writing a new function `ri2py` that handles this, as shown below: +.. code-block:: python + import rpy2.robjects as robjects + + def my_ri2py(obj): + res = robjects.default_ri2py(obj) + if isinstance(res, robjects.RVector) and (len(res) == 1): + res = res[0] + return res + + robjects.ri2py = my_ri2py + +Once this is done, we can verify immediately that this is working with: + +>>> pi = robjects.r.pi +>> type(pi) +<type 'float'> +>>> + + Examples ======== @@ -381,7 +414,8 @@ will hopefully be used as a cookbook. -.. testcode:: robjects +.. code-block:: python + import rpy2.robjects as robjects import array @@ -434,7 +468,7 @@ print(r.anova(lm_D9)) lm_D90 = r.lm("weight ~ group - 1") - r.summary(lm_D90) + print(r.summary(lm_D90)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------- Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW! Studies have shown that voting for your favorite open source project, along with a healthy diet, reduces your potential for chronic lameness and boredom. Vote Now at http://www.sourceforge.net/community/cca08 _______________________________________________ rpy-list mailing list rpy-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rpy-list