Revision: 421
          http://rpy.svn.sourceforge.net/rpy/?rev=421&view=rev
Author:   lgautier
Date:     2008-03-08 02:08:21 -0800 (Sat, 08 Mar 2008)

Log Message:
-----------
- pydoc string for Rvector.subset
- fixed operations (+, -, etc..) on Rvector

Modified Paths:
--------------
    trunk/sandbox/rpy_nextgen/robjects/__init__.py

Modified: trunk/sandbox/rpy_nextgen/robjects/__init__.py
===================================================================
--- trunk/sandbox/rpy_nextgen/robjects/__init__.py      2008-03-08 09:46:52 UTC 
(rev 420)
+++ trunk/sandbox/rpy_nextgen/robjects/__init__.py      2008-03-08 10:08:21 UTC 
(rev 421)
@@ -74,6 +74,7 @@
         s = str.join(os.linesep, s)
         return s
 
+
 class Rvector(Robject):
     """ R vector-like object. Items in those instances can
        be accessed with the method "__getitem__" ("[" operator),
@@ -85,12 +86,18 @@
         else:
             self._sexp = defaultPy2RMapper(self, o)
 
-    def subset(self, *args):
-        """ Subset the "R-way.", using R's "[" function """
+    def subset(self, *args, **kwargs):
+        """ Subset the "R-way.", using R's "[" function. 
+           In a nutshell, R indexing differs from Python's with
+           - indexing can be done with integers or strings (that are 'names')
+           - integer indexing starts at one
+           - negative integer indexing means exclusion of the given integers
+           - an index is itself a vector of elements to select
+        """
         for a in args:
             if not isinstance(a, rinterface.SexpVector):
                 raise(TypeError("Subset only take R vectors"))
-        res = rinterface.globalEnv.get("[")([self._sexp, ] + args)#, drop=drop)
+        res = rinterface.globalEnv.get("[")([self._sexp, ] + args, **kwargs)
         return res
 
     def __getitem__(self, i):
@@ -98,31 +105,31 @@
         return res
 
     def __add__(self, x):
-        res = r.__getattribute__("+")(self, x)
+        res = r.get("+")(self, x)
         return res
 
     def __sub__(self, x):
-        res = r.__getattribute__("-")(self, x)
+        res = r.get("-")(self, x)
         return res
 
     def __mul__(self, x):
-        res = r.__getattribute__("*")(self, x)
+        res = r.get("*")(self, x)
         return res
 
     def __div__(self, x):
-        res = r.__getattribute__("/")(self, x)
+        res = r.get("/")(self, x)
         return res
 
     def __divmod__(self, x):
-        res = r.__getattribute__("%%")(self, x)
+        res = r.get("%%")(self, x)
         return res
 
     def __or__(self, x):
-        res = r.__getattribute__("|")(self, x)
+        res = r.get("|")(self, x)
         return res
 
     def __and__(self, x):
-        res = r.__getattribute__("&")(self, x)
+        res = r.get("&")(self, x)
         return res
 
 
@@ -175,6 +182,7 @@
         res = r.get("@")(self, attr)
         return res
 
+    
 class R(object):
     _instance = None
 


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: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
rpy-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rpy-list

Reply via email to