Bug 13758 - Wishlist: as.raw [or similar] support for tcl strings
Wishlist: as.raw [or similar] support for tcl strings
Status: CLOSED FIXED
Product: R
Classification: Unclassified
Component: Wishlist
old
All Linux
: P5 normal
Assigned To: Jitterbug compatibility account
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2009-06-16 02:39 UTC by Jitterbug compatibility account
Modified: 2009-06-16 02:39 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jitterbug compatibility account 2009-06-16 02:39:36 UTC
From: whorfin@pixar.com
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

Comment 1 Jitterbug compatibility account 2009-08-17 12:13:00 UTC
NOTES:
 Added for 2.10.0
Comment 2 Jitterbug compatibility account 2009-08-17 12:13:07 UTC
Audit (from Jitterbug):
Wed Jun 17 16:14:40 2009	ripley	moved from incoming to Add-ons
Mon Aug 17 07:13:06 2009	ripley	changed notes
Mon Aug 17 07:13:07 2009	ripley	moved from Add-ons to wishlst-fulfilled