From wdunlap at tibco.com  Mon Jan 19 19:44:25 2009
From: wdunlap at tibco.com (William Dunlap)
Date: Mon, 19 Jan 2009 10:44:25 -0800
Subject: [Rd] Floating point excepting when cbind()ing a matrix of grobs
	(orenvironments) with a 0-column matrix
In-Reply-To: <f8e6ff050901190718j65b829c5q68be435a14d8ae9b@mail.gmail.com>
References: <f8e6ff050901190718j65b829c5q68be435a14d8ae9b@mail.gmail.com>
Message-ID: <77EB52C6DD32BA4D87471DCD70C8D7007BD906@NA-PA-VBE03.na.tibco.com>

I think the following patch to src/main/bind.c fixes it up.
If the length of an argument to [cr]bind is 0 then it wont't
try to add any data from it to the output any more, just as
is done with the other modes of data.  It was getting the FPE
from i%k when k==0.

Index: src/main/bind.c
===================================================================
--- src/main/bind.c     (revision 47617)
+++ src/main/bind.c     (working copy)
@@ -1218,10 +1218,12 @@
                case LISTSXP:
                    PROTECT(u = coerceVector(u, mode));
                    k = LENGTH(u);
-                   idx = (!isMatrix(u)) ? rows : k;
-                   for (i = 0; i < idx; i++)
-                       SET_VECTOR_ELT(result, n++,
-                                      duplicate(VECTOR_ELT(u, i % k)));
+                   if (k>0) {
+                       idx = (!isMatrix(u)) ? rows : k;
+                       for (i = 0; i < idx; i++)
+                           SET_VECTOR_ELT(result, n++,
+                                          duplicate(VECTOR_ELT(u, i %
k)));
+                   }
                    UNPROTECT(1);
                    break;
                default:

Bill Dunlap
TIBCO Software Inc - Spotfire Division
wdunlap tibco.com  

> -----Original Message-----
> From: r-devel-bounces at r-project.org 
> [mailto:r-devel-bounces at r-project.org] On Behalf Of hadley wickham
> Sent: Monday, January 19, 2009 7:18 AM
> To: r-devel at r-project.org
> Subject: [Rd] Floating point excepting when cbind()ing a 
> matrix of grobs (orenvironments) with a 0-column matrix
> 
> library(grid)
> e <- rectGrob()
> # OR:
> # e <- environment()
> 
> a <- matrix(list(e), ncol = 1, nrow = 2)
> b <- matrix(ncol = 0, nrow = 2)
> 
> cbind(a, b)
> 
> cbind(a, b)
> 
> This reliably crashes R for me.
> 
> I realise this is a rather esoteric error condition, but it crops up
> for me when creating matrices of grobs to be turned into a ggplot2
> plot.
> 
> Hadley
> 
> -- 
> http://had.co.nz/
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
> 



[Rd] Floating point excepting when cbind()ing a matrix of grobs (orenvironments) with a 0-column matrix
William Dunlap