[Rd] tcltk wish: Add tclObj.raw method for converting raw vectors to tclObj

Charlie Friedemann cfriedem at gmail.com
Wed Jun 6 05:27:12 CEST 2012


I have submitted a bug report / wish to the R Bug tracker (https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=14939), but I'd like to make this request here as well. Essentially, I was wondering if it would be possible to add another c routine to be called by as.TclObj for raw vectors. Right now, as.raw() is supported for objects of type "tclObj" (IIRC this change was made in 2.9 after someone requested it), however there is no corresponding C routine for converting raw vectors into tclObj.  

I suppose the best way to do this is to create a new C routine in the tcltk package analogous to the other RObject to Tcl object routines: RTcl_ObjFromRawVector. Create a new tclObj pointer, use Tcl_NewByteArrayObj() from the Tcl C API to create a byte array of the same length as the input raw vector, and then loop through the RAWSXP object assigning each element in the vector to the Tcl byte array. I'd be happy to submit code for this patch if requested.

This would be extremely helpful. I am using tcl binary sockets and this functionality would allow me to both read and write raw vectors directly from/to Tcl. I can only read raw vectors directly at the moment and have to use strings to get a raw vector into Tcl.

There's also the possibility that this has been attempted and for some reason it didn't work, but I don't know why that would be the case. Thank you for your consideration!


More information about the R-devel mailing list