[Rd] RFC: rawConnection (was "loop connections")

Duncan Murdoch murdoch at stats.uwo.ca
Fri Sep 2 12:39:02 CEST 2005


dhinds at sonic.net wrote:
> Duncan Murdoch <murdoch at stats.uwo.ca> wrote:
> 
> 
>>I think the cost of duplicating as.raw is worse than the cost of using 
>>extra memory.  If the lack of symmetry bothers you, a solution is to 
>>require a raw object as input.
> 
> 
> It wouldn't exactly be duplicating as.raw since this way of converting
> to raw is actually to do nothing at all, just to treat the object as
> if it is already raw.  But, I don't have a strong opinion.

I haven't looked at as.raw, but I think it does something other than 
that.  For example,

rawToChar(as.raw(1:10)) gives

"\001\002\003\004\005\006\a\b\t\n"

I don't know if there's a way to do exactly what you're proposing.  One 
argument against it is that the bytes for an object may vary from 
platform to platform (big versus little endian, maybe 32 vs 64 bit), 
whereas we try to make R code platform independent when we can.

>> > Currently, textConnection() makes a copy for "r" connections
>>
>>>but writes directly to an R object for "w" connections.  The "w" case
>>>is buggy; you can crash R by removing the target object while the
>>>connection is being used.  I'm not familiar enough with R internals to
>>>know how to fix that.  Maybe the object has to be searched for every
>>>time the connection is used, to avoid potentially stale pointers?
> 
> 
>>I've been having an argument with some other people about something 
>>related to this.  I think they would say that the language doesn't 
>>support writing to a variable.
> 
> 
> I tried changing textConnection output connections to look up the
> destination object on every access and that seems to solve the problem
> without being terribly expensive.
> 
> 
>>If so, then a binary mode rawConnection (with mention of the way to 
>>convert in the Rd file) would be good enough for me.
> 
> 
> It seems we are coming back to something close to what I had
> originally implemented?

Probably!  The differences I still know about are:

  - I'd like the name to reflect the data source, so rawConnection or 
something similar rather than overloading textConnection.

  - It needs a man page, or to be included on the textConnection man page.

Duncan



More information about the R-devel mailing list