multi-dimension array of raw

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

multi-dimension array of raw

Gerald Jansen
I would like to store and manipulate large sets of marker genotypes
compactly using "raw" data arrays. This works fine for vectors or
matrices, but I run into the error shown in the example below as soon
as I try to use 3 dimensional arrays (eg. animal x marker x allele).

> a <- array(as.raw(1:6),c(2,3))
> a
     [,1] [,2] [,3]
[1,]   01   03   05
[2,]   02   04   06
> a[1,] <- raw(3)
> a
     [,1] [,2] [,3]
[1,]   00   00   00
[2,]   02   04   06
> b <- array(as.raw(1:6),c(1,2,3))
> b[1,,]
     [,1] [,2] [,3]
[1,]   01   03   05
[2,]   02   04   06
> b[1,1,] <- raw(3)
Error: incompatible types (from raw to raw) in array subset assignment

I can work around this with computed indices, but I wonder if this is
expected behaviour.

Gerald Jansen

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: multi-dimension array of raw

Duncan Murdoch
On 6/20/2006 6:24 PM, Gerald Jansen wrote:

> I would like to store and manipulate large sets of marker genotypes
> compactly using "raw" data arrays. This works fine for vectors or
> matrices, but I run into the error shown in the example below as soon
> as I try to use 3 dimensional arrays (eg. animal x marker x allele).
>
>> a <- array(as.raw(1:6),c(2,3))
>> a
>      [,1] [,2] [,3]
> [1,]   01   03   05
> [2,]   02   04   06
>> a[1,] <- raw(3)
>> a
>      [,1] [,2] [,3]
> [1,]   00   00   00
> [2,]   02   04   06
>> b <- array(as.raw(1:6),c(1,2,3))
>> b[1,,]
>      [,1] [,2] [,3]
> [1,]   01   03   05
> [2,]   02   04   06
>> b[1,1,] <- raw(3)
> Error: incompatible types (from raw to raw) in array subset assignment
>
> I can work around this with computed indices, but I wonder if this is
> expected behaviour.

I don't think so.  It is just an unimplemented case.

Using raw in this way is a fairly unusual thing to do, and you've come
across a case nobody thought of implementing.

Indexing is a "primitive" function, so it's hard for you to fix this.
It needs to be done in the internals of R (function ArrayAssign, in
src/main/subassign.c, if you're interested).  I'll try to take a look
and see if it looks reasonable to add.

Duncan Murdoch

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: multi-dimension array of raw

Duncan Murdoch
In reply to this post by Gerald Jansen
On 6/20/2006 6:24 PM, Gerald Jansen wrote:

> I would like to store and manipulate large sets of marker genotypes
> compactly using "raw" data arrays. This works fine for vectors or
> matrices, but I run into the error shown in the example below as soon
> as I try to use 3 dimensional arrays (eg. animal x marker x allele).
>
>> a <- array(as.raw(1:6),c(2,3))
>> a
>      [,1] [,2] [,3]
> [1,]   01   03   05
> [2,]   02   04   06
>> a[1,] <- raw(3)
>> a
>      [,1] [,2] [,3]
> [1,]   00   00   00
> [2,]   02   04   06
>> b <- array(as.raw(1:6),c(1,2,3))
>> b[1,,]
>      [,1] [,2] [,3]
> [1,]   01   03   05
> [2,]   02   04   06
>> b[1,1,] <- raw(3)
> Error: incompatible types (from raw to raw) in array subset assignment
>
> I can work around this with computed indices, but I wonder if this is
> expected behaviour.

This is now fixed in r-devel and r-patched.

Duncan Murdoch

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: multi-dimension array of raw

Prof Brian Ripley
In reply to this post by Duncan Murdoch
On Tue, 20 Jun 2006, Duncan Murdoch wrote:

> On 6/20/2006 6:24 PM, Gerald Jansen wrote:
>> I would like to store and manipulate large sets of marker genotypes
>> compactly using "raw" data arrays. This works fine for vectors or
>> matrices, but I run into the error shown in the example below as soon
>> as I try to use 3 dimensional arrays (eg. animal x marker x allele).
>>
>>> a <- array(as.raw(1:6),c(2,3))
>>> a
>>      [,1] [,2] [,3]
>> [1,]   01   03   05
>> [2,]   02   04   06
>>> a[1,] <- raw(3)
>>> a
>>      [,1] [,2] [,3]
>> [1,]   00   00   00
>> [2,]   02   04   06
>>> b <- array(as.raw(1:6),c(1,2,3))
>>> b[1,,]
>>      [,1] [,2] [,3]
>> [1,]   01   03   05
>> [2,]   02   04   06
>>> b[1,1,] <- raw(3)
>> Error: incompatible types (from raw to raw) in array subset assignment
>>
>> I can work around this with computed indices, but I wonder if this is
>> expected behaviour.
>
> I don't think so.  It is just an unimplemented case.
>
> Using raw in this way is a fairly unusual thing to do, and you've come
> across a case nobody thought of implementing.

Actually, raw arrays were originally not implemented at all, so this is
`expected behaviour', and you may well encounter other unimplemented areas
as no one has attempted to implement them comprehensively. Please report
them, but on R-devel not here.

--
Brian D. Ripley,                  [hidden email]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html