[R-gregmisc-users] SF.net SVN: r-gregmisc:[1814] trunk/gtools/R/smartbind.R
Brought to you by:
warnes
From: <wa...@us...> - 2014-05-28 00:15:00
|
Revision: 1814 http://sourceforge.net/p/r-gregmisc/code/1814 Author: warnes Date: 2014-05-28 00:14:56 +0000 (Wed, 28 May 2014) Log Message: ----------- smartbind: Convert non-native type columns (except factor) to character. Modified Paths: -------------- trunk/gtools/R/smartbind.R Modified: trunk/gtools/R/smartbind.R =================================================================== --- trunk/gtools/R/smartbind.R 2014-04-18 18:11:20 UTC (rev 1813) +++ trunk/gtools/R/smartbind.R 2014-05-28 00:14:56 UTC (rev 1814) @@ -63,18 +63,33 @@ " End:", end, " Column:", col, "\n", sep="") + if ("factor" %in% classVec) { newclass <- "character" } else - newclass <- classVec + newclass <- classVec[1] + ## Coerce everything that isn't a native type to character + if(! (newclass %in% c("logical", "integer", "numeric", + "complex", "character", "raw") )) + { + newclass <- "character" + warning("Converting non-atomic type column '", col, + "' to type character.") + } + retval[[col]] <- as.vector(rep(fill,nrows), mode=newclass) } - retval[[col]][start:end] <- as.vector(block[,col], - mode=class(retval[[col]])) + mode <- class(retval[[col]]) + if(mode=="character") + vals <- as.character(block[,col]) + else + vals <- block[,col] + + retval[[col]][start:end] <- as.vector(vals, mode=mode) } start <- end+1 blockIndex <- blockIndex+1 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |