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

whorfin at pixar.com whorfin at pixar.com
Mon Jun 15 23:45:09 CEST 2009

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

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

A good discussion of the basics of this issue for general tcl embedding can be
found here:

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
and timeouts, modes, and line control for RS232 ports aren't supported at all on
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


More information about the R-devel mailing list