Nathaniel Smith wrote: > There are several times in R when it is valuable to explicitly leave > an argument missing. For example, when extracting a row from a matrix: > >> m <- matrix(1:4, nrow=2) >> m[2] # Flat indexing > [1] 2 >> m[2, ] # Note the comma! > [1] 2 4 > > However, there is currently no way to support this (rather > idiosyncratic) syntax in rpy2.
In the case of extracting elements from a matrix, there is a way (working in R, as well as in rpy2): m[2, TRUE] # Note the TRUE ! [1] 2 4 There are otherwise other functions checking for "missing" arguments, but I postponed the resolution of that to a post-2.0 release. (I thought that they are not as frequent at when using "["). > The attached patch adds a function rpy2.rinterface.getMissingArgSexp > which returns an Sexp wrapping the magic R_MissingArg object. With > this patch, the following becomes possible: > >>>> m = r.matrix([1, 2, 3, 4], nrow=2) >>>> r["["](m, 2, rpy2.rinterface.getMissingArgSexp()) > > Patch includes tests, which pass for me. I'd be more keen on defining the missing magic, as well as NULL and the NA_* group as user-immutable objects in a module (rather than functions). import rpy2.robjects as ro import rpy2.rinterface.defs as rstuff # to use your example above m = ro.r.matrix(ro.IntVector([1,2,3,4]), nrow=2) ro.r["["](m, 2, rstuff.MISSING) # but right now the following is already working: ro.r["["](m, 2, True) I started looked at how this could happen with the NA_* group, but got too busy on the day job otherwise and had to interrupt half-way through. One point of concern is that that those variables are not valid until R is initialized. This is rather easy to solve when considering the use of functions such as getNA_REAL() or getMissingArg(), but not when considering non-callable objects in a module. After several (unsuccessful) attempts, I am now seeing the use of a module-mimicking class with getters as one way. L. > -- Nathaniel > > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------------ > Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM) > software. With Adobe AIR, Ajax developers can use existing skills and code to > build responsive, highly engaging applications that combine the power of local > resources and data with the reach of the web. Download the Adobe AIR SDK and > Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com > > > ------------------------------------------------------------------------ > > _______________________________________________ > rpy-list mailing list > rpy-list@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/rpy-list ------------------------------------------------------------------------------ Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM) software. With Adobe AIR, Ajax developers can use existing skills and code to build responsive, highly engaging applications that combine the power of local resources and data with the reach of the web. Download the Adobe AIR SDK and Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com _______________________________________________ rpy-list mailing list rpy-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rpy-list