In the new version 0.90.0, rbind won't take a vector and a matrix from me, but works OK if I coerce the vector to a matrix. The following was run on a new session (i.e., no prior work), and has been duplicated on 2 machines: an SGI running Irix 6.5, and an Intel box running Red Hat Linux 6.0. Either case works fine in version 0.65.1.> t3 <- c(.5, .5) > t4 <- matrix(rnorm(8), 4, 2) > t3[1] 0.5 0.5> t4[,1] [,2] [1,] 1.0701582 -0.40888504 [2,] -0.2961581 -1.73051884 [3,] 0.6191254 0.05958328 [4,] -1.3844937 0.81863361> dim(t3) <- c(1,2) (make vector a matrix) > rbind(t3, t4)[,1] [,2] [1,] 0.5000000 0.50000000 (so OK when vector coerced) [2,] 1.0701582 -0.40888504 [3,] -0.2961581 -1.73051884 [4,] 0.6191254 0.05958328 [5,] -1.3844937 0.81863361> > t3 <- c(.5, .5) (reassign t3 as a vector) > dim(t3)NULL> > rbind(t3, t4)Process R segmentation violation (core dumped) at Tue Nov 23 11:28:05 1999 -------------------------------------------------------------------------- Am I missing something? Has anyone else come across this problem? Or is this a new feature? I don't see anything in the documentation; indeed, it says (in the help for cbind and rbind): When the arguments consist of a mix of matrices and vectors the number of columns (rosw) of the result is determined by the number of columns (rows) of the matrix arguments. Any vectors have their values recycled or subsetted to achieve this length. Thanks, Matt -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Tue, 23 Nov 1999 mcw@ln.nimh.nih.gov wrote:> > In the new version 0.90.0, rbind won't take a vector and a matrix from me, > but works OK if I coerce the vector to a matrix. The following was run on > a new session (i.e., no prior work), and has been duplicated on 2 > machines: an SGI running Irix 6.5, and an Intel box running Red Hat Linux > 6.0.Ok, this is an interesting problem in rbind when there are no names and a matrix and a vector and deparse_level=1 The reason we segfault is basically (gdb) print nrows(R_NilValue) $59 = 1076101128 which seems like a bad idea At lines 1328ff we have a bug where we iterate over the number of rows of "u", forgetting that after line 1315 u points to the (nonexistent) dimnames rather than to the matrix. I'm testing a fix. -thomas Thomas Lumley Assistant Professor, Biostatistics University of Washington, Seattle -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Ok, here's a patch: -thomas *** /usr/local/src/R-0.90.0/src/main/bind.c Fri Nov 12 15:33:28 1999 --- /biostat/faculty0/thomas/Rarchive/r-devel/R/src/main/bind.c Tue Nov 23 09:40:25 1999 *************** *** 1299,1305 **** } /* Adjustment of dimnames attributes. */ if (have_rnames | have_cnames) { ! SEXP nam, tnam; PROTECT(dn = allocVector(VECSXP, 2)); if (have_rnames) nam = VECTOR(dn)[0] = allocVector(STRSXP, rows); --- 1299,1305 ---- } /* Adjustment of dimnames attributes. */ if (have_rnames | have_cnames) { ! SEXP nam, tnam,v; PROTECT(dn = allocVector(VECSXP, 2)); if (have_rnames) nam = VECTOR(dn)[0] = allocVector(STRSXP, rows); *************** *** 1312,1323 **** if (isMatrix(u)) { ! u = getAttrib(u, R_DimNamesSymbol); ! tnam = GetRowNames(u); if (have_cnames && GetColNames(dn) == R_NilValue ! && GetColNames(u) != R_NilValue) ! SetColNames(dn, duplicate(GetColNames(u))); /* cbind() doesn't test have_?names BEFORE tnam!=Nil..:*/ if (have_rnames) { --- 1312,1323 ---- if (isMatrix(u)) { ! v = getAttrib(u, R_DimNamesSymbol); ! tnam = GetRowNames(v); if (have_cnames && GetColNames(dn) == R_NilValue ! && GetColNames(v) != R_NilValue) ! SetColNames(dn, duplicate(GetColNames(v))); /* cbind() doesn't test have_?names BEFORE tnam!=Nil..:*/ if (have_rnames) { -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._