From murdoch at stats.uwo.ca  Fri Sep  2 12:39:02 2005
From: murdoch at stats.uwo.ca (Duncan Murdoch)
Date: Fri, 02 Sep 2005 06:39:02 -0400
Subject: [Rd] RFC: rawConnection (was "loop connections")
In-Reply-To: <df8jev$2l6$1@sea.gmane.org>
References: <dedndn$daj$1@sea.gmane.org>	<17168.15848.291481.473231@stat.math.ethz.ch>	<df5b90$1ba$1@sea.gmane.org>
	<431667BC.7050906@stats.uwo.ca>	<df62er$jab$1@sea.gmane.org>
	<4316D8B3.3040504@stats.uwo.ca>	<df7c03$s62$1@sea.gmane.org>
	<4317B6B5.30709@stats.uwo.ca> <df8jev$2l6$1@sea.gmane.org>
Message-ID: <43182BC6.5080700@stats.uwo.ca>

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



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