Revision: 723
          http://rpy.svn.sourceforge.net/rpy/?rev=723&view=rev
Author:   lgautier
Date:     2008-12-19 21:39:45 +0000 (Fri, 19 Dec 2008)

Log Message:
-----------
Edits to specify a little more what is happening with function calls

Modified Paths:
--------------
    rpy2/branches/version_2.0.x/doc/source/rinterface.rst
    rpy2/branches/version_2.0.x/doc/source/robjects.rst

Modified: rpy2/branches/version_2.0.x/doc/source/rinterface.rst
===================================================================
--- rpy2/branches/version_2.0.x/doc/source/rinterface.rst       2008-12-19 
20:58:12 UTC (rev 722)
+++ rpy2/branches/version_2.0.x/doc/source/rinterface.rst       2008-12-19 
21:39:45 UTC (rev 723)
@@ -604,10 +604,26 @@
 >>> s = sum(x)
 >>> s[0]
 6
->>>
 
+.. rubric:: Named arguments
 
-.. index::
+Named arguments to an R function can be specified just the way
+they would be with any other regular Python function.
+
+>>> rnorm = rinterface.globalEnv.get("rnorm")
+>>> rnorm(rinterface.SexpVector([1, ], rinterface.INTSXP), 
+          mean = rinterface.SexpVector([2, ], rinterface.INTSXP))[0]
+0.32796768001636134
+
+There are however frequent names for R parameters causing problems: all the 
names with a *dot*. using such parameters for an R function will either require
+to:
+
+* use the special syntax `**kwargs` on a dictionary with the named parameters
+
+* use the method :meth:`rcall`.  
+
+
+.. Index::
    single: rcall; order of parameters
 
 .. rubric:: Order for named parameters
@@ -623,15 +639,17 @@
 
    import rpy2.rlike.container as rpc
    args = rpc.ArgsDict()
-   args['x'] = rinterface.SexpVector([1,2,3], rinterface.INTSXP)
-   args[None] = rinterface.SexpVector([4,5], rinterface.INTSXP)
-   args['y'] = rinterface.SexpVector([6, ], rinterface.INTSXP)
+   args['x'] = rinterface.IntSexpVector([1,2,3], rinterface.INTSXP)
+   args[None] = rinterface.IntSexpVector([4,5], rinterface.INTSXP)
+   args['y'] = rinterface.IntSexpVector([6, ], rinterface.INTSXP)
    rlist = rinterface.baseNameSpaceEnv['list']
    rl = rlist.rcall(args.items())
 
 >>> [x for x in rl.do_slot("names")]
 ['x', '', 'y']
 
+
+
 .. index::
    single: closureEnv
 

Modified: rpy2/branches/version_2.0.x/doc/source/robjects.rst
===================================================================
--- rpy2/branches/version_2.0.x/doc/source/robjects.rst 2008-12-19 20:58:12 UTC 
(rev 722)
+++ rpy2/branches/version_2.0.x/doc/source/robjects.rst 2008-12-19 21:39:45 UTC 
(rev 723)
@@ -461,18 +461,29 @@
 >>> rnorm = robjects.r.rnorm
 >>> plot(rnorm(100), ylab="random")
 
-In Python, arguments to a function are split into two groups:
+This is all looking fine and simple until R parameters with names 
+such as `na.rm` are encountered. In those cases, using the special
+syntax `**kwargs` is one way to go.
 
-* A first group for which parameters are in defined order
+Let's take an example in R:
 
-* A second group for which parameters are associated a name/keyword,
-  and a default value. In that second group the order is lost, as it is
-  passed as a Python dictionary.
+.. code-block:: r
 
-Those two groups can be used in function calls.
+   sum(0, na.rm = TRUE)
 
+In Python it can then write:
 
-The class inherits from the class
+.. code-block:: python
+
+   from rpy2 import robjects
+
+   myparams = {'na.rm': True}
+   robjects.r.sum(0, **myparams)
+
+Things are also not always that simple, as the use of dictionary does
+ensure that the order in which the parameters are passed is conserved.
+
+The R functions as defined in :mod:`rpy2.robjects` inherit from the class
 :class:`rpy2.rinterface.SexpClosure`, and further documentation
 on the behavior of function can be found in Section 
:ref:`rinterface-functions`.
 


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list

Reply via email to