From deepayan.sarkar at gmail.com  Wed May 21 21:26:27 2008
From: deepayan.sarkar at gmail.com (Deepayan Sarkar)
Date: Wed, 21 May 2008 12:26:27 -0700
Subject: [Rd] rawToChar(raw(0))
In-Reply-To: <59d7961d0805211012v2bbf7dbes9b8f2f5aeed2c08d@mail.gmail.com>
References: <59d7961d0805211012v2bbf7dbes9b8f2f5aeed2c08d@mail.gmail.com>
Message-ID: <eb555e660805211226h3daac0a5o10c3caf93cb5e01@mail.gmail.com>

On 5/21/08, Henrik Bengtsson <hb at stat.berkeley.edu> wrote:
> Hi,
>
>  right now we have (on R v2.7.0 patched (2008-04-23 r45466)) that:
>
>  > rawToChar(raw(0))
>  [1] ""
>  > rawToChar(raw(0), multiple=TRUE)
>  character(0)
>
>  Is this intended or should both return character(0)?  Personally, I
>  would prefer that an empty input vector returns an empty output
>  vector.

I don't see why; rawToChar(, multiple=FALSE) is meant to be a map from
an n-vector to a scalar. Why should there be an exception when n==0?
Would you expect

mean(numeric(0))

to return numeric(0)?

> Same should then apply to charToRaw(), but right now we get:
>
>  > x <- character(0)
>  > charToRaw(x)
>  Error in charToRaw(x) : argument must be a character vector of length 1

The error message says it all: charToRaw() maps a scalar to an
n-vector. For vectors of length > 1, it uses the first element with a
warning.

No comments on the rest.

-Deepayan

>  [...]



[Rd] rawToChar(raw(0))
Deepayan Sarkar