Currently one cannot coerce R "logical" vectors to a numpy vector:

>>> import rpy2.rinterface as ri
>>> np.asarray(ri.SexpVector([True, False], ri.LGLSXP))
[...]
ValueError: unsupported typestring

The problem is that rpy2 is describing that SEXP as containing an
array of 32-bit (!) booleans. That is actually correct; R (for
whatever odd reason) uses full int's to store boolean values, and in
fact NA_LOGICAL is 0x80000000. However, numpy only understands 8-bit
booleans.

Since numpy is effectively the only consumer for the sexp array
interface, and in any case it is nice to convert R logical vectors to
a type that allows the 3-way TRUE/FALSE/NA distinction, the attached
patch changes array.c so that rpy2 will report logical vectors as
composed of integers rather than booleans.

Tests included, but I haven't run them, because current tip fails to
build for me (rpy_device.c:1175: error: `DevDesc' undeclared...).

-- 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

Reply via email to