[Rd] Wishlist: as.raw [or similar] support for tcl strings (PR#13758)

From: <whorfin_at_pixar.com>
Date: Mon, 15 Jun 2009 23:45:09 +0200 (CEST)


Full_Name: Rick Sayre
Version: 2.9.0
OS: windows, os x, linux
Submission from: (NULL) (138.72.153.236)

if a tcl "string" contains binary data, there is a problem getting this data to R, since there appears to be no way to get "raw" data without NULL interpretation. Here is a simple example. The data should be Here are 1<one NULL>Here is 2<two NULLs>And finally three<three NULLS>
> tq <- .Tcl("set tcls [binary format H*
\"48657265206172652031004865726520697320320000416E642066696E616C6C79207468726565000000\"]") #tclvalue stops returning data after the first NULL
> tclvalue("tcls")

[1] "Here are 1"
#interestingly, as.character gets more, but gets confused
> as.character(tq)

[1] "Here" "are" "1" "is" "2" "finally" "three"
> # we confirm that the tcl representation does indeed have the NULLs:
> .Tcl("binary scan $tcls H* tmps")

<Tcl> 1
> tclvalue("tmps")

[1] "48657265206172652031004865726520697320320000416e642066696e616c6c79207468726565000000"

I would naively suggest something like tclrawvalue() and/or as.raw() utilizing Tcl_GetByteArrayFromObj

A good discussion of the basics of this issue for general tcl embedding can be found here:
http://www2.tcl.tk/1180

For those who might be wondering "what the heck are you doing trying to pass binary data from tcl?", the answer is that non-blocking I/O does not work on windows,
and timeouts, modes, and line control for RS232 ports aren't supported at all on R.
Using tcl provides a nice portable way to do this in R, but currently requires converting everything to ascii encodings since the binary data fails to make it across.

Cheers

   --Rick



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Tue 16 Jun 2009 - 11:37:41 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 16 Jun 2009 - 12:36:04 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive