Revision: 703 http://rpy.svn.sourceforge.net/rpy/?rev=703&view=rev Author: lgautier Date: 2008-11-23 12:56:34 +0000 (Sun, 23 Nov 2008)
Log Message: ----------- backported edits to the doc Modified Paths: -------------- rpy2/branches/version_2.0.x/doc/source/index.rst rpy2/branches/version_2.0.x/doc/source/rinterface.rst rpy2/branches/version_2.0.x/doc/source/robjects.rst Added Paths: ----------- rpy2/branches/version_2.0.x/doc/source/numpy.rst Property Changed: ---------------- rpy2/branches/version_2.0.x/doc/ Property changes on: rpy2/branches/version_2.0.x/doc ___________________________________________________________________ Modified: svn:mergeinfo - /rpy2/trunk/doc:691-700 + /rpy2/trunk/doc:691-700,702 Modified: rpy2/branches/version_2.0.x/doc/source/index.rst =================================================================== --- rpy2/branches/version_2.0.x/doc/source/index.rst 2008-11-23 12:52:29 UTC (rev 702) +++ rpy2/branches/version_2.0.x/doc/source/index.rst 2008-11-23 12:56:34 UTC (rev 703) @@ -8,6 +8,7 @@ overview introduction robjects + numpy rinterface rpy_classic rlike Copied: rpy2/branches/version_2.0.x/doc/source/numpy.rst (from rev 702, rpy2/trunk/doc/source/numpy.rst) =================================================================== --- rpy2/branches/version_2.0.x/doc/source/numpy.rst (rev 0) +++ rpy2/branches/version_2.0.x/doc/source/numpy.rst 2008-11-23 12:56:34 UTC (rev 703) @@ -0,0 +1,85 @@ + +Numpy +===== + +A popular solution for scientific computing with Python is :mod:`numpy` +(previous instances were :mod:`Numpy` and :mod:`numarray`). + +:mod:`rpy2` has features for facilitating the integration with code using +:mod:`numpy` in both directions: from `rpy2` to `numpy`, and from `numpy` +to `rpy2`. + +High-level interface +-------------------- + +From `rpy2` to `numpy`: +^^^^^^^^^^^^^^^^^^^^^^^ + +Vectors can be converted to :mod:`numpy` arrays using +:meth:`array` or :meth:`asarray`:: + + import numpy + + ltr = robjects.r.letters + ltr_np = numpy.array(ltr) + +This behavior is inherited from the low-level interface, +and is means that the objects presents an interface recognized by +`numpy`, and that interface used to know the structure of the object. + + + +From `numpy` to `rpy2`: +^^^^^^^^^^^^^^^^^^^^^^^ + +The conversion of `numpy` objects to `rpy2` objects can be +activated by importing the module :mod:`numpy2ri`:: + + import rpy2.robjects.numpy2ri + +That import alone is sufficient to switch an automatic conversion +of `numpy` objects into `rpy2` objects. + + +.. note:: + + Why make this an optional import, while it could have been included + in the function :func:`py2ri` (as done in the original patch + submitted for that function) ? + + Although both are valid and reasonable options, the design decision + was taken in order to decouple `rpy2` from `numpy` the most, and + do not assume that having `numpy` installed automatically + meant that a programmer wanted to use it. + + +.. literalinclude:: ../../rpy/robjects/numpy2ri.py + + + +Low-level interface +------------------- + +The :class:`rpy2.rinterface.SexpVector` objects are made to +behave like arrays, as defined in the Python package :mod:`numpy`. + +The functions :func:`numpy.array` and :func:`numpy.asarray` can +be used construct `numpy` arrays: + + +>>> import numpy +>>> rx = rinterface.SexpVector([1,2,3,4], rinterface.INTSXP) +>>> nx = numpy.array(rx) +>>> nx_nc = numpy.asarray(rx) + + +.. note:: + when using :meth:`asarray`, the data are not copied. + +>>> rx[2] +3 +>>> nx_nc[2] = 42 +>>> rx[2] +42 +>>> + Modified: rpy2/branches/version_2.0.x/doc/source/rinterface.rst =================================================================== --- rpy2/branches/version_2.0.x/doc/source/rinterface.rst 2008-11-23 12:52:29 UTC (rev 702) +++ rpy2/branches/version_2.0.x/doc/source/rinterface.rst 2008-11-23 12:56:34 UTC (rev 703) @@ -366,34 +366,8 @@ -.. index:: - pair: SexpVector; numpy +.. rubric:: Constructors -Numpy -^^^^^ - -The :class:`SexpVector` objects are made to behave like arrays as defined -in the Python package :mod:`numpy`. - -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) ->>> nx_nc = numpy.asarray(rx) - - -.. note:: - when using :meth:`asarray`, the data are not copied. - ->>> rx[2] -3 ->>> nx_nc[2] = 42 ->>> rx[2] -42 ->>> - .. autoclass:: rpy2.rinterface.SexpVector(obj, sexptype, copy) :show-inheritance: :members: Modified: rpy2/branches/version_2.0.x/doc/source/robjects.rst =================================================================== --- rpy2/branches/version_2.0.x/doc/source/robjects.rst 2008-11-23 12:52:29 UTC (rev 702) +++ rpy2/branches/version_2.0.x/doc/source/robjects.rst 2008-11-23 12:56:34 UTC (rev 703) @@ -1,4 +1,5 @@ + ******************** High-level interface ******************** @@ -311,58 +312,6 @@ .. index:: - pair: RVector; numpy - -Numpy ------ - -A popular solution for scientific computing with Python is :mod:`numpy` -(previous instances were :mod:`Numpy` and :mod:`numarray`). - -:mod:`rpy2` has features for facilitating the integration with code using -:mod:`numpy` in both directions: from `rpy2` to `numpy`, and from `numpy` -to `rpy2`. - - -From `rpy2` to `numpy`: -^^^^^^^^^^^^^^^^^^^^^^^ - -Vectors can be converted to :mod:`numpy` arrays using -:meth:`array` or :meth:`asarray`:: - - import numpy - ltr = robjects.r.letters - ltr_np = numpy.array(ltr) - -Refer to the documentation for :class:`rinterface.SexpVector` -for further details. - -From `numpy` to `rpy2`: -^^^^^^^^^^^^^^^^^^^^^^^ - -The conversion of `numpy` objects to `rpy2` objects can be -activated by importing the module :mod:`numpy2ri`:: - - import rpy2.robjects.numpy2ri - -That import alone is sufficient to switch an automatic conversion -of `numpy` objects into `rpy2` objects. - - -.. note:: - - Why make this an optional import, while it could have been included - in the function :func:`py2ri` (as done in the original patch - submitted for that function) ? - - Although both are valid and reasonable options, the design decision - was taken in order to decouple `rpy2` from `numpy` the most, and - do not assume that having `numpy` installed automatically - meant that a programmer wanted to use it. - - - -.. index:: pair: robjects;REnvironment pair: robjects;globalEnv This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ rpy-list mailing list rpy-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rpy-list