From hin-tak.leung at cimr.cam.ac.uk  Fri Jan 27 15:46:01 2006
From: hin-tak.leung at cimr.cam.ac.uk (Hin-Tak Leung)
Date: Fri, 27 Jan 2006 14:46:01 +0000
Subject: [Rd] rbind/cbind unimplemented for raw (RAWSXP) types. (PR#8529)
In-Reply-To: <20060127142659.8FC43CD16@slim.kubism.ku.dk>
References: <20060127142659.8FC43CD16@slim.kubism.ku.dk>
Message-ID: <43DA3229.6040209@cimr.cam.ac.uk>

hin-tak.leung at cimr.cam.ac.uk wrote:
> Full_Name: Hin-Tak Leung
> Version: R 2.2.1
> OS: x86_64-redhat-linux-gnu
> Submission from: (NULL) (131.111.186.92)
> 
> 
> rbind/cbind is unimplemented for raw (RAWSXP) types.
> 
> I have a working patch implementing the functionality,
> to follow.

Attached in ready-to-patch form and also insert (white spaces
will go wrong) here. Please review, comment and possibly commit,
and hope to see it in R 2.3.x

====================
--- src/main/bind.c.orig        2005-10-06 11:25:22.000000000 +0100
+++ src/main/bind.c     2006-01-27 11:55:32.000000000 +0000
@@ -997,6 +997,7 @@
      case CPLXSXP:
      case STRSXP:
      case VECSXP:
+    case RAWSXP:
         break;
         /* we don't handle expressions: we could, but coercion of a matrix
            to an expression is not ideal */
@@ -1164,6 +1165,18 @@
             }
         }
      }
+    else if (mode == RAWSXP) {
+       for (t = args; t != R_NilValue; t = CDR(t)) {
+           u = PRVALUE(CAR(t));
+           if (isMatrix(u) || length(u) >= lenmin) {
+               u = coerceVector(u, RAWSXP);
+               k = LENGTH(u);
+               idx = (!isMatrix(u)) ? rows : k;
+               for (i = 0; i < idx; i++)
+                   RAW(result)[n++] = RAW(u)[i % k];
+           }
+       }
+    }
      else {
         for (t = args; t != R_NilValue; t = CDR(t)) {
             u = PRVALUE(CAR(t));
@@ -1385,6 +1398,21 @@
             }
         }
      }
+    else if (mode == RAWSXP) {
+       for (t = args; t != R_NilValue; t = CDR(t)) {
+           u = PRVALUE(CAR(t));
+           if (isMatrix(u) || length(u) >= lenmin) {
+               u = coerceVector(u, RAWSXP);
+               k = LENGTH(u);
+               idx = (isMatrix(u)) ? nrows(u) : (k > 0);
+               for (i = 0; i < idx; i++)
+                   for (j = 0; j < cols; j++)
+                       RAW(result)[i + n + (j * rows)]
+                           = RAW(u)[(i + j * idx) % k];
+               n += idx;
+           }
+       }
+    }
      else {
         for (t = args; t != R_NilValue; t = CDR(t)) {
             u = PRVALUE(CAR(t));
================================


[Rd] rbind/cbind unimplemented for raw (RAWSXP) types. (PR#8529)
Hin-Tak Leung