[R-gregmisc-users] SF.net SVN: r-gregmisc:[1966] trunk/gdata
Brought to you by:
warnes
From: <wa...@us...> - 2015-04-25 16:23:33
|
Revision: 1966 http://sourceforge.net/p/r-gregmisc/code/1966 Author: warnes Date: 2015-04-25 16:23:31 +0000 (Sat, 25 Apr 2015) Log Message: ----------- Modfy write.fwf() to properly handle matrix argument, avoiding conversion to dataframe unless rownames=TRUE. Add corresponding unit tests. Modified Paths: -------------- trunk/gdata/R/write.fwf.R trunk/gdata/tests/test.humanReadable.Rout.save trunk/gdata/tests/test.reorder.factor.Rout.save trunk/gdata/tests/tests.write.fwf.Rout.save trunk/gdata/tests/unitTests/runit.write.fwf.R Modified: trunk/gdata/R/write.fwf.R =================================================================== --- trunk/gdata/R/write.fwf.R 2015-04-25 09:11:54 UTC (rev 1965) +++ trunk/gdata/R/write.fwf.R 2015-04-25 16:23:31 UTC (rev 1966) @@ -25,6 +25,16 @@ { ## --- Setup --- + dapply <- function(x, FUN, ..., simplify=TRUE) + { + if(is.data.frame(x)) + return(sapply(x, FUN, ..., simplify=simplify)) + else if(is.matrix(x)) + return(apply(x, 2, FUN, ...)) + else + stop("x must be a data.frame or a matrix") + } + if(!(is.data.frame(x) || is.matrix(x))) stop("'x' must be a data.frame or matrix") if(length(na) > 1) @@ -39,7 +49,7 @@ if(rownames) { - x <- cbind(rownames(x), x) + x <- cbind(rownames(x), as.data.frame(x)) rowColVal <- ifelse(!is.null(rowCol), rowCol, "row") colnames(x)[1] <- rowColVal } @@ -69,22 +79,26 @@ stringsAsFactors=FALSE) ## Which columns are numeric like - isNum <- apply(x, 2, is.numeric) + isNum <- dapply(x, is.numeric) ## is.numeric picks also Date and POSIXt - isNum <- isNum & !(apply(x, 2, inherits, what="Date") | - apply(x, 2, inherits, what="POSIXt")) + isNum <- isNum & !(dapply(x, inherits, what="Date") | + dapply(x, inherits, what="POSIXt")) ## Which columns are factors --> convert them to character - isFac <- apply(x, 2, is.factor) - x[, isFac] <- apply(x[, isFac, drop=FALSE], 2, as.character) + isFac <- dapply(x, is.factor) + if(any(isFac)) + ## This conditional is necessary because if x is a matrix, even if + ## all(isFAC==FALSE), this assignment will coerce it to mode + ## character. This isn't a problem for dataframes. + x[, isFac] <- sapply(x[, isFac, drop=FALSE], as.character) ## Collect information about how format() will format columns. ## We need to get this info now, since format will turn all columns to character - tmp <- apply(x, 2, format.info, ...) + tmp <- dapply(x, format.info, ..., simplify=FALSE) + if(is.matrix(x)) tmp <- as.data.frame(tmp) tmp1 <- sapply(tmp, length) tmp <- t(as.data.frame(tmp)) retFormat$width <- tmp[, 1] - ## Collect other details for numeric columns if(any(isNum)) { ## Numeric columns with digits @@ -100,6 +114,9 @@ ## --- Format --- + ## store original object in 'y' + y <- x + ## Formatting (to character) for(i in 1:nCol) { if(widthNULL) { @@ -112,17 +129,17 @@ ## following test to "fiddle" with the value in 'na' argument since - ## NA should not increase the width of column with width 1, while wider ## value for 'na' should increase the width - test <- is.na(x[, i]) + test <- is.na(y[, i]) ## Make a copy to make sure we get character after first format() - Date class caused problems x2 <- character(length=nRow) ## Add formatted values - x2[!test] <- format(x[!test, i], justify=justify, width=tmp, ...) + x2[!test] <- format(y[!test, i], justify=justify, width=tmp, ...) ## Add 'na' value x2[test] <- na ## Replace the original x[, i] <- x2 ## Collect width (again) - tmp2 <- format.info(x[, i], ...)[1] + tmp2 <- format.info(x2, ...)[1] ## Reformat if 'na' value change the width of the column if(tmp2 != retFormat[i, "width"]) { retFormat[i, "width"] <- tmp2 @@ -139,7 +156,7 @@ ## Number of levels for "non-numeric"" columns if(any(!isNum)) { - retFormat[!isNum, "nlevels"] <- apply(x[, !isNum, drop=FALSE], 2, + retFormat[!isNum, "nlevels"] <- dapply(x[, !isNum, drop=FALSE], function(z) length(unique(z))) } Modified: trunk/gdata/tests/test.humanReadable.Rout.save =================================================================== --- trunk/gdata/tests/test.humanReadable.Rout.save 2015-04-25 09:11:54 UTC (rev 1965) +++ trunk/gdata/tests/test.humanReadable.Rout.save 2015-04-25 16:23:31 UTC (rev 1966) @@ -1,14 +1,12 @@ -R version 3.1.2 (2014-10-31) -- "Pumpkin Helmet" -Copyright (C) 2014 The R Foundation for Statistical Computing +R version 3.2.0 (2015-04-16) -- "Full of Ingredients" +Copyright (C) 2015 The R Foundation for Statistical Computing Platform: x86_64-apple-darwin13.4.0 (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. - Natural language support but running in an English locale - R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. @@ -27,13 +25,13 @@ gdata: to automatically download and install the perl gdata: libaries needed to support Excel XLS and XLSX formats. -Attaching package: ‘gdata’ +Attaching package: 'gdata' -The following object is masked from ‘package:stats’: +The following object is masked from 'package:stats': nobs -The following object is masked from ‘package:utils’: +The following object is masked from 'package:utils': object.size @@ -65,26 +63,26 @@ + humanReadable(x=IEC2, standard="Unix", width=3)) [,1] [,2] [,3] [,4] [,5] [,6] [1,] " 2 B " " 2 B " " 2 B " " 2 B " " 2 B " " 2 B " - [2,] "1.26838 kB" "1.268 kB" " 1.3 kB" "1.25729 KiB" "1.257 KiB" " 1.3 KiB" - [3,] " 1.2285 MB" "1.228 MB" " 1.2 MB" "1.83751 MiB" "1.838 MiB" " 1.8 MiB" - [4,] "1.24401 GB" "1.244 GB" " 1.2 GB" "1.26666 GiB" "1.267 GiB" " 1.3 GiB" - [5,] "1.47565 TB" "1.476 TB" " 1.5 TB" " 1.4234 TiB" "1.423 TiB" " 1.4 TiB" - [6,] "1.36687 PB" "1.367 PB" " 1.4 PB" "1.32499 PiB" "1.325 PiB" " 1.3 PiB" - [7,] "1.21324 EB" "1.213 EB" " 1.2 EB" "1.54391 EiB" "1.544 EiB" " 1.5 EiB" - [8,] "1.37186 ZB" "1.372 ZB" " 1.4 ZB" " 1.233 ZiB" "1.233 ZiB" " 1.2 ZiB" - [9,] "1.19468 YB" "1.195 YB" " 1.2 YB" "1.21258 YiB" "1.213 YiB" " 1.2 YiB" -[10,] "1201.13 YB" " 1201 YB" "1201 YB" "1489.01 YiB" " 1489 YiB" "1489 YiB" + [2,] "1.19855 kB" "1.199 kB" " 1.2 kB" "1.23404 KiB" "1.234 KiB" " 1.2 KiB" + [3,] "1.20686 MB" "1.207 MB" " 1.2 MB" "1.24529 MiB" "1.245 MiB" " 1.2 MiB" + [4,] "1.24218 GB" "1.242 GB" " 1.2 GB" "1.19621 GiB" "1.196 GiB" " 1.2 GiB" + [5,] "1.20157 TB" "1.202 TB" " 1.2 TB" "1.21737 TiB" "1.217 TiB" " 1.2 TiB" + [6,] "1.26255 PB" "1.263 PB" " 1.3 PB" "1.57268 PiB" "1.573 PiB" " 1.6 PiB" + [7,] "1.35911 EB" "1.359 EB" " 1.4 EB" "1.18177 EiB" "1.182 EiB" " 1.2 EiB" + [8,] " 1.2033 ZB" "1.203 ZB" " 1.2 ZB" "1.49049 ZiB" " 1.49 ZiB" " 1.5 ZiB" + [9,] "1.35332 YB" "1.353 YB" " 1.4 YB" "1.84401 YiB" "1.844 YiB" " 1.8 YiB" +[10,] " 1723.7 YB" " 1724 YB" "1724 YB" "1216.27 YiB" " 1216 YiB" "1216 YiB" [,7] [,8] [,9] [1,] " 2 B" " 2 B" " 2 B" - [2,] "1.25729 K" "1.257 K" " 1.3 K" - [3,] "1.83751 M" "1.838 M" " 1.8 M" - [4,] "1.26666 G" "1.267 G" " 1.3 G" - [5,] " 1.4234 T" "1.423 T" " 1.4 T" - [6,] "1.32499 P" "1.325 P" " 1.3 P" - [7,] "1.54391 E" "1.544 E" " 1.5 E" - [8,] " 1.233 Z" "1.233 Z" " 1.2 Z" - [9,] "1.21258 Y" "1.213 Y" " 1.2 Y" -[10,] "1489.01 Y" " 1489 Y" "1489 Y" + [2,] "1.23404 K" "1.234 K" " 1.2 K" + [3,] "1.24529 M" "1.245 M" " 1.2 M" + [4,] "1.19621 G" "1.196 G" " 1.2 G" + [5,] "1.21737 T" "1.217 T" " 1.2 T" + [6,] "1.57268 P" "1.573 P" " 1.6 P" + [7,] "1.18177 E" "1.182 E" " 1.2 E" + [8,] "1.49049 Z" " 1.49 Z" " 1.5 Z" + [9,] "1.84401 Y" "1.844 Y" " 1.8 Y" +[10,] "1216.27 Y" " 1216 Y" "1216 Y" > > # Auto units, specify digits > cbind(humanReadable(x=SI2, standard="SI", width=NULL, digits=7), @@ -101,37 +99,37 @@ + humanReadable(x=IEC2, standard="Unix", width=NULL, digits=1)) [,1] [,2] [,3] [,4] [1,] " 1.5000000 B " " 1.500 B " " 1.50 B " " 1.5 B " - [2,] " 1.2683780 kB" " 1.268 kB" " 1.27 kB" " 1.3 kB" - [3,] " 1.2284981 MB" " 1.228 MB" " 1.23 MB" " 1.2 MB" - [4,] " 1.2440094 GB" " 1.244 GB" " 1.24 GB" " 1.2 GB" - [5,] " 1.4756474 TB" " 1.476 TB" " 1.48 TB" " 1.5 TB" - [6,] " 1.3668711 PB" " 1.367 PB" " 1.37 PB" " 1.4 PB" - [7,] " 1.2132416 EB" " 1.213 EB" " 1.21 EB" " 1.2 EB" - [8,] " 1.3718619 ZB" " 1.372 ZB" " 1.37 ZB" " 1.4 ZB" - [9,] " 1.1946775 YB" " 1.195 YB" " 1.19 YB" " 1.2 YB" -[10,] "1201.1346574 YB" "1201.135 YB" "1201.13 YB" "1201.1 YB" + [2,] " 1.1985486 kB" " 1.199 kB" " 1.20 kB" " 1.2 kB" + [3,] " 1.2068563 MB" " 1.207 MB" " 1.21 MB" " 1.2 MB" + [4,] " 1.2421751 GB" " 1.242 GB" " 1.24 GB" " 1.2 GB" + [5,] " 1.2015680 TB" " 1.202 TB" " 1.20 TB" " 1.2 TB" + [6,] " 1.2625549 PB" " 1.263 PB" " 1.26 PB" " 1.3 PB" + [7,] " 1.3591145 EB" " 1.359 EB" " 1.36 EB" " 1.4 EB" + [8,] " 1.2033002 ZB" " 1.203 ZB" " 1.20 ZB" " 1.2 ZB" + [9,] " 1.3533151 YB" " 1.353 YB" " 1.35 YB" " 1.4 YB" +[10,] "1723.7026620 YB" "1723.703 YB" "1723.70 YB" "1723.7 YB" [,5] [,6] [,7] [,8] [1,] " 1.5000000 B " " 1.500 B " " 1.50 B " " 1.5 B " - [2,] " 1.2572859 KiB" " 1.257 KiB" " 1.26 KiB" " 1.3 KiB" - [3,] " 1.8375086 MiB" " 1.838 MiB" " 1.84 MiB" " 1.8 MiB" - [4,] " 1.2666626 GiB" " 1.267 GiB" " 1.27 GiB" " 1.3 GiB" - [5,] " 1.4234036 TiB" " 1.423 TiB" " 1.42 TiB" " 1.4 TiB" - [6,] " 1.3249855 PiB" " 1.325 PiB" " 1.32 PiB" " 1.3 PiB" - [7,] " 1.5439083 EiB" " 1.544 EiB" " 1.54 EiB" " 1.5 EiB" - [8,] " 1.2329980 ZiB" " 1.233 ZiB" " 1.23 ZiB" " 1.2 ZiB" - [9,] " 1.2125791 YiB" " 1.213 YiB" " 1.21 YiB" " 1.2 YiB" -[10,] "1489.0123170 YiB" "1489.012 YiB" "1489.01 YiB" "1489.0 YiB" + [2,] " 1.2340441 KiB" " 1.234 KiB" " 1.23 KiB" " 1.2 KiB" + [3,] " 1.2452876 MiB" " 1.245 MiB" " 1.25 MiB" " 1.2 MiB" + [4,] " 1.1962114 GiB" " 1.196 GiB" " 1.20 GiB" " 1.2 GiB" + [5,] " 1.2173697 TiB" " 1.217 TiB" " 1.22 TiB" " 1.2 TiB" + [6,] " 1.5726781 PiB" " 1.573 PiB" " 1.57 PiB" " 1.6 PiB" + [7,] " 1.1817693 EiB" " 1.182 EiB" " 1.18 EiB" " 1.2 EiB" + [8,] " 1.4904906 ZiB" " 1.490 ZiB" " 1.49 ZiB" " 1.5 ZiB" + [9,] " 1.8440055 YiB" " 1.844 YiB" " 1.84 YiB" " 1.8 YiB" +[10,] "1216.2741325 YiB" "1216.274 YiB" "1216.27 YiB" "1216.3 YiB" [,9] [,10] [,11] [,12] [1,] " 1.5000000 B" " 1.500 B" " 1.50 B" " 1.5 B" - [2,] " 1.2572859 K" " 1.257 K" " 1.26 K" " 1.3 K" - [3,] " 1.8375086 M" " 1.838 M" " 1.84 M" " 1.8 M" - [4,] " 1.2666626 G" " 1.267 G" " 1.27 G" " 1.3 G" - [5,] " 1.4234036 T" " 1.423 T" " 1.42 T" " 1.4 T" - [6,] " 1.3249855 P" " 1.325 P" " 1.32 P" " 1.3 P" - [7,] " 1.5439083 E" " 1.544 E" " 1.54 E" " 1.5 E" - [8,] " 1.2329980 Z" " 1.233 Z" " 1.23 Z" " 1.2 Z" - [9,] " 1.2125791 Y" " 1.213 Y" " 1.21 Y" " 1.2 Y" -[10,] "1489.0123170 Y" "1489.012 Y" "1489.01 Y" "1489.0 Y" + [2,] " 1.2340441 K" " 1.234 K" " 1.23 K" " 1.2 K" + [3,] " 1.2452876 M" " 1.245 M" " 1.25 M" " 1.2 M" + [4,] " 1.1962114 G" " 1.196 G" " 1.20 G" " 1.2 G" + [5,] " 1.2173697 T" " 1.217 T" " 1.22 T" " 1.2 T" + [6,] " 1.5726781 P" " 1.573 P" " 1.57 P" " 1.6 P" + [7,] " 1.1817693 E" " 1.182 E" " 1.18 E" " 1.2 E" + [8,] " 1.4904906 Z" " 1.490 Z" " 1.49 Z" " 1.5 Z" + [9,] " 1.8440055 Y" " 1.844 Y" " 1.84 Y" " 1.8 Y" +[10,] "1216.2741325 Y" "1216.274 Y" "1216.27 Y" "1216.3 Y" > > # Single unit, specify width > cbind(humanReadable(x=SI1, units="GB", standard="SI", width=7), @@ -146,26 +144,26 @@ + ) [,1] [,2] [,3] [,4] [,5] [,6] [1,] "5e-10 GB" "5e-10 GB" "5e-10 GB" "5e-10 GiB" "5e-10 GiB" "5e-10 GiB" - [2,] "6e-07 GB" "6e-07 GB" "6e-07 GB" "6e-07 GiB" "6e-07 GiB" "6e-07 GiB" - [3,] "7e-04 GB" "7e-04 GB" "7e-04 GB" "7e-04 GiB" "7e-04 GiB" "7e-04 GiB" + [2,] "8e-07 GB" "8e-07 GB" "8e-07 GB" "7e-07 GiB" "7e-07 GiB" "7e-07 GiB" + [3,] "8e-04 GB" "8e-04 GB" "8e-04 GB" "8e-04 GiB" "8e-04 GiB" "8e-04 GiB" [4,] "8e-01 GB" "8e-01 GB" "8e-01 GB" "8e-01 GiB" "8e-01 GiB" "8e-01 GiB" - [5,] "7e+02 GB" "7e+02 GB" "7e+02 GB" "3e+02 GiB" "3e+02 GiB" "3e+02 GiB" - [6,] "8e+05 GB" "8e+05 GB" "8e+05 GB" "7e+05 GiB" "7e+05 GiB" "7e+05 GiB" + [5,] "8e+02 GB" "8e+02 GB" "8e+02 GB" "6e+02 GiB" "6e+02 GiB" "6e+02 GiB" + [6,] "8e+05 GB" "8e+05 GB" "8e+05 GB" "6e+05 GiB" "6e+05 GiB" "6e+05 GiB" [7,] "8e+08 GB" "8e+08 GB" "8e+08 GB" "8e+08 GiB" "8e+08 GiB" "8e+08 GiB" - [8,] "8e+11 GB" "8e+11 GB" "8e+11 GB" "5e+11 GiB" "5e+11 GiB" "5e+11 GiB" - [9,] "7e+14 GB" "7e+14 GB" "7e+14 GB" "9e+14 GiB" "9e+14 GiB" "9e+14 GiB" -[10,] "8e+17 GB" "8e+17 GB" "8e+17 GB" "6e+17 GiB" "6e+17 GiB" "6e+17 GiB" + [8,] "8e+11 GB" "8e+11 GB" "8e+11 GB" "9e+11 GiB" "9e+11 GiB" "9e+11 GiB" + [9,] "8e+14 GB" "8e+14 GB" "8e+14 GB" "4e+14 GiB" "4e+14 GiB" "4e+14 GiB" +[10,] "7e+17 GB" "7e+17 GB" "7e+17 GB" "8e+17 GiB" "8e+17 GiB" "8e+17 GiB" [,7] [,8] [,9] [1,] "5e-10 G" "5e-10 G" "5e-10 G" - [2,] "6e-07 G" "6e-07 G" "6e-07 G" - [3,] "7e-04 G" "7e-04 G" "7e-04 G" + [2,] "7e-07 G" "7e-07 G" "7e-07 G" + [3,] "8e-04 G" "8e-04 G" "8e-04 G" [4,] "8e-01 G" "8e-01 G" "8e-01 G" - [5,] "3e+02 G" "3e+02 G" "3e+02 G" - [6,] "7e+05 G" "7e+05 G" "7e+05 G" + [5,] "6e+02 G" "6e+02 G" "6e+02 G" + [6,] "6e+05 G" "6e+05 G" "6e+05 G" [7,] "8e+08 G" "8e+08 G" "8e+08 G" - [8,] "5e+11 G" "5e+11 G" "5e+11 G" - [9,] "9e+14 G" "9e+14 G" "9e+14 G" -[10,] "6e+17 G" "6e+17 G" "6e+17 G" + [8,] "9e+11 G" "9e+11 G" "9e+11 G" + [9,] "4e+14 G" "4e+14 G" "4e+14 G" +[10,] "8e+17 G" "8e+17 G" "8e+17 G" > > # Single unit, specify digits > cbind(humanReadable(x=SI1, units="GB", standard="SI", width=NULL, digits=7), @@ -183,37 +181,37 @@ + ) [,1] [,2] [,3] [,4] [1,] "5.000000e-10 GB" "5.00e-10 GB" "5.0e-10 GB" "5e-10 GB" - [2,] "6.388137e-07 GB" "6.39e-07 GB" "6.4e-07 GB" "6e-07 GB" - [3,] "7.101117e-04 GB" "7.10e-04 GB" "7.1e-04 GB" "7e-04 GB" - [4,] "8.188110e-01 GB" "8.19e-01 GB" "8.2e-01 GB" "8e-01 GB" - [5,] "6.706597e+02 GB" "6.71e+02 GB" "6.7e+02 GB" "7e+02 GB" - [6,] "8.067884e+05 GB" "8.07e+05 GB" "8.1e+05 GB" "8e+05 GB" - [7,] "7.758668e+08 GB" "7.76e+08 GB" "7.8e+08 GB" "8e+08 GB" - [8,] "7.861707e+11 GB" "7.86e+11 GB" "7.9e+11 GB" "8e+11 GB" - [9,] "7.495958e+14 GB" "7.50e+14 GB" "7.5e+14 GB" "7e+14 GB" -[10,] "7.655714e+17 GB" "7.66e+17 GB" "7.7e+17 GB" "8e+17 GB" + [2,] "7.792994e-07 GB" "7.79e-07 GB" "7.8e-07 GB" "8e-07 GB" + [3,] "7.796269e-04 GB" "7.80e-04 GB" "7.8e-04 GB" "8e-04 GB" + [4,] "8.033561e-01 GB" "8.03e-01 GB" "8.0e-01 GB" "8e-01 GB" + [5,] "8.314840e+02 GB" "8.31e+02 GB" "8.3e+02 GB" "8e+02 GB" + [6,] "8.018065e+05 GB" "8.02e+05 GB" "8.0e+05 GB" "8e+05 GB" + [7,] "8.032533e+08 GB" "8.03e+08 GB" "8.0e+08 GB" "8e+08 GB" + [8,] "7.736007e+11 GB" "7.74e+11 GB" "7.7e+11 GB" "8e+11 GB" + [9,] "8.033881e+14 GB" "8.03e+14 GB" "8.0e+14 GB" "8e+14 GB" +[10,] "6.856332e+17 GB" "6.86e+17 GB" "6.9e+17 GB" "7e+17 GB" [,5] [,6] [,7] [,8] [1,] "4.656613e-10 GiB" "4.66e-10 GiB" "4.7e-10 GiB" "5e-10 GiB" - [2,] "6.058649e-07 GiB" "6.06e-07 GiB" "6.1e-07 GiB" "6e-07 GiB" - [3,] "7.437373e-04 GiB" "7.44e-04 GiB" "7.4e-04 GiB" "7e-04 GiB" - [4,] "7.890501e-01 GiB" "7.89e-01 GiB" "7.9e-01 GiB" "8e-01 GiB" - [5,] "2.665461e+02 GiB" "2.67e+02 GiB" "2.7e+02 GiB" "3e+02 GiB" - [6,] "6.781352e+05 GiB" "6.78e+05 GiB" "6.8e+05 GiB" "7e+05 GiB" - [7,] "7.658425e+08 GiB" "7.66e+08 GiB" "7.7e+08 GiB" "8e+08 GiB" - [8,] "4.681329e+11 GiB" "4.68e+11 GiB" "4.7e+11 GiB" "5e+11 GiB" - [9,] "8.705167e+14 GiB" "8.71e+14 GiB" "8.7e+14 GiB" "9e+14 GiB" -[10,] "6.227605e+17 GiB" "6.23e+17 GiB" "6.2e+17 GiB" "6e+17 GiB" + [2,] "7.138398e-07 GiB" "7.14e-07 GiB" "7.1e-07 GiB" "7e-07 GiB" + [3,] "7.600841e-04 GiB" "7.60e-04 GiB" "7.6e-04 GiB" "8e-04 GiB" + [4,] "8.231780e-01 GiB" "8.23e-01 GiB" "8.2e-01 GiB" "8e-01 GiB" + [5,] "5.678312e+02 GiB" "5.68e+02 GiB" "5.7e+02 GiB" "6e+02 GiB" + [6,] "5.506880e+05 GiB" "5.51e+05 GiB" "5.5e+05 GiB" "6e+05 GiB" + [7,] "8.221636e+08 GiB" "8.22e+08 GiB" "8.2e+08 GiB" "8e+08 GiB" + [8,] "8.721612e+11 GiB" "8.72e+11 GiB" "8.7e+11 GiB" "9e+11 GiB" + [9,] "4.356026e+14 GiB" "4.36e+14 GiB" "4.4e+14 GiB" "4e+14 GiB" +[10,] "8.080586e+17 GiB" "8.08e+17 GiB" "8.1e+17 GiB" "8e+17 GiB" [,9] [,10] [,11] [,12] [1,] "4.656613e-10 G" "4.66e-10 G" "4.7e-10 G" "5e-10 G" - [2,] "6.058649e-07 G" "6.06e-07 G" "6.1e-07 G" "6e-07 G" - [3,] "7.437373e-04 G" "7.44e-04 G" "7.4e-04 G" "7e-04 G" - [4,] "7.890501e-01 G" "7.89e-01 G" "7.9e-01 G" "8e-01 G" - [5,] "2.665461e+02 G" "2.67e+02 G" "2.7e+02 G" "3e+02 G" - [6,] "6.781352e+05 G" "6.78e+05 G" "6.8e+05 G" "7e+05 G" - [7,] "7.658425e+08 G" "7.66e+08 G" "7.7e+08 G" "8e+08 G" - [8,] "4.681329e+11 G" "4.68e+11 G" "4.7e+11 G" "5e+11 G" - [9,] "8.705167e+14 G" "8.71e+14 G" "8.7e+14 G" "9e+14 G" -[10,] "6.227605e+17 G" "6.23e+17 G" "6.2e+17 G" "6e+17 G" + [2,] "7.138398e-07 G" "7.14e-07 G" "7.1e-07 G" "7e-07 G" + [3,] "7.600841e-04 G" "7.60e-04 G" "7.6e-04 G" "8e-04 G" + [4,] "8.231780e-01 G" "8.23e-01 G" "8.2e-01 G" "8e-01 G" + [5,] "5.678312e+02 G" "5.68e+02 G" "5.7e+02 G" "6e+02 G" + [6,] "5.506880e+05 G" "5.51e+05 G" "5.5e+05 G" "6e+05 G" + [7,] "8.221636e+08 G" "8.22e+08 G" "8.2e+08 G" "8e+08 G" + [8,] "8.721612e+11 G" "8.72e+11 G" "8.7e+11 G" "9e+11 G" + [9,] "4.356026e+14 G" "4.36e+14 G" "4.4e+14 G" "4e+14 G" +[10,] "8.080586e+17 G" "8.08e+17 G" "8.1e+17 G" "8e+17 G" > > > stopifnot( is.object_sizes(as.object_sizes( 2^(1:30) ) ) ) @@ -240,4 +238,4 @@ > > proc.time() user system elapsed - 0.411 0.048 0.455 + 0.368 0.047 0.415 Modified: trunk/gdata/tests/test.reorder.factor.Rout.save =================================================================== --- trunk/gdata/tests/test.reorder.factor.Rout.save 2015-04-25 09:11:54 UTC (rev 1965) +++ trunk/gdata/tests/test.reorder.factor.Rout.save 2015-04-25 16:23:31 UTC (rev 1966) @@ -1,14 +1,12 @@ -R version 3.1.2 (2014-10-31) -- "Pumpkin Helmet" -Copyright (C) 2014 The R Foundation for Statistical Computing -Platform: x86_64-unknown-linux-gnu (64-bit) +R version 3.2.0 (2015-04-16) -- "Full of Ingredients" +Copyright (C) 2015 The R Foundation for Statistical Computing +Platform: x86_64-apple-darwin13.4.0 (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. - Natural language support but running in an English locale - R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. @@ -31,20 +29,23 @@ > library(gdata) gdata: read.xls support for 'XLS' (Excel 97-2004) files ENABLED. -gdata: read.xls support for 'XLSX' (Excel 2007+) files ENABLED. +gdata: Unable to load perl libaries needed by read.xls() +gdata: to support 'XLSX' (Excel 2007+) files. -Attaching package: ‘gdata’ +gdata: Run the function 'installXLSXsupport()' +gdata: to automatically download and install the perl +gdata: libaries needed to support Excel XLS and XLSX formats. -The following object is masked from ‘package:stats’: +Attaching package: 'gdata' +The following object is masked from 'package:stats': + nobs -The following object is masked from ‘package:utils’: +The following object is masked from 'package:utils': object.size -Warning message: -S3 methods ‘print.object_size’, ‘c.object_size’ were declared in NAMESPACE but not found > > ( m2 <- reorder(m, X=c(3, 2, 1)) ) [1] a b c @@ -57,4 +58,4 @@ > > proc.time() user system elapsed - 0.512 0.070 0.638 + 0.300 0.049 0.345 Modified: trunk/gdata/tests/tests.write.fwf.Rout.save =================================================================== --- trunk/gdata/tests/tests.write.fwf.Rout.save 2015-04-25 09:11:54 UTC (rev 1965) +++ trunk/gdata/tests/tests.write.fwf.Rout.save 2015-04-25 16:23:31 UTC (rev 1966) @@ -1,7 +1,7 @@ -R version 3.1.0 Patched (2014-05-26 r65771) -- "Spring Dance" -Copyright (C) 2014 The R Foundation for Statistical Computing -Platform: x86_64-apple-darwin13.1.0 (64-bit) +R version 3.2.0 (2015-04-16) -- "Full of Ingredients" +Copyright (C) 2015 The R Foundation for Statistical Computing +Platform: x86_64-apple-darwin13.4.0 (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. @@ -25,8 +25,13 @@ > library(gdata) gdata: read.xls support for 'XLS' (Excel 97-2004) files ENABLED. -gdata: read.xls support for 'XLSX' (Excel 2007+) files ENABLED. +gdata: Unable to load perl libaries needed by read.xls() +gdata: to support 'XLSX' (Excel 2007+) files. +gdata: Run the function 'installXLSXsupport()' +gdata: to automatically download and install the perl +gdata: libaries needed to support Excel XLS and XLSX formats. + Attaching package: 'gdata' The following object is masked from 'package:stats': @@ -80,7 +85,7 @@ > ## NA should be - > write.fwf(x=testData, na="-") num1 num2 num3 int1 fac1 fac2 cha1 cha2 Date POSIXt - 1 - - 1 - f q - 1900-01-01 1900-01-01 01:01:01 + 1 - - 1 - f q - 1900-01-01 1900-01-01 01:01:01 2 1.0 733070.3 2 a g r longer - 1900-01-01 01:01:01 3 1.5 1214213.8 3 b h s y 1900-01-01 1900-01-01 01:01:01 4 2.0 553823.8 4 c i t x 1900-01-01 1900-01-01 01:01:01 @@ -90,21 +95,21 @@ 8 4.0 1053686.6 6 g m x t 1900-01-01 1900-01-01 01:01:01 9 4.5 971024.2 7 h n y s 1900-01-01 1900-01-01 01:01:01 10 5.0 631193.4 8 i o z r 1900-01-01 1900-01-01 01:01:01 - - 5.5 879431.1 9 hjh - - q 1900-01-01 1900-01-01 01:01:01 +- 5.5 879431.1 9 hjh - - q 1900-01-01 1900-01-01 01:01:01 > ## NA should be -NA- > write.fwf(x=testData, na="-NA-") num1 num2 num3 int1 fac1 fac2 cha1 cha2 Date POSIXt - 1 -NA- -NA- 1 -NA- f q -NA- 1900-01-01 1900-01-01 01:01:01 - 2 1.0 733070.3 2 a g r longer -NA- 1900-01-01 01:01:01 - 3 1.5 1214213.8 3 b h s y 1900-01-01 1900-01-01 01:01:01 - 4 2.0 553823.8 4 c i t x 1900-01-01 1900-01-01 01:01:01 - 5 2.5 1085022.9 -NA- d j u w 1900-01-01 -NA- - 6 3.0 571063.9 4 e k v v 1900-01-01 1900-01-01 01:01:01 - 7 3.5 606718.4 5 f l w u 1900-01-01 1900-01-01 01:01:01 - 8 4.0 1053686.6 6 g m x t 1900-01-01 1900-01-01 01:01:01 - 9 4.5 971024.2 7 h n y s 1900-01-01 1900-01-01 01:01:01 - 10 5.0 631193.4 8 i o z r 1900-01-01 1900-01-01 01:01:01 --NA- 5.5 879431.1 9 hjh -NA- -NA- q 1900-01-01 1900-01-01 01:01:01 + 1 -NA- -NA- 1 -NA- f q -NA- 1900-01-01 1900-01-01 01:01:01 + 2 1.0 733070.3 2 a g r longer -NA- 1900-01-01 01:01:01 + 3 1.5 1214213.8 3 b h s y 1900-01-01 1900-01-01 01:01:01 + 4 2.0 553823.8 4 c i t x 1900-01-01 1900-01-01 01:01:01 + 5 2.5 1085022.9 -NA- d j u w 1900-01-01 -NA- + 6 3.0 571063.9 4 e k v v 1900-01-01 1900-01-01 01:01:01 + 7 3.5 606718.4 5 f l w u 1900-01-01 1900-01-01 01:01:01 + 8 4.0 1053686.6 6 g m x t 1900-01-01 1900-01-01 01:01:01 + 9 4.5 971024.2 7 h n y s 1900-01-01 1900-01-01 01:01:01 +10 5.0 631193.4 8 i o z r 1900-01-01 1900-01-01 01:01:01 +-NA- 5.5 879431.1 9 hjh -NA- -NA- q 1900-01-01 1900-01-01 01:01:01 > > ## Some other separator than space > write.fwf(testData[, 1:4], sep="-mySep-") @@ -231,4 +236,4 @@ > > proc.time() user system elapsed - 0.388 0.041 0.422 + 0.413 0.044 0.448 Modified: trunk/gdata/tests/unitTests/runit.write.fwf.R =================================================================== --- trunk/gdata/tests/unitTests/runit.write.fwf.R 2015-04-25 09:11:54 UTC (rev 1965) +++ trunk/gdata/tests/unitTests/runit.write.fwf.R 2015-04-25 16:23:31 UTC (rev 1966) @@ -59,9 +59,17 @@ digits=c(0, 1), exp=c(0, 0), stringsAsFactors=FALSE) - formatInfo <- write.fwf(testData[, c("num1", "num2")], formatInfo=TRUE) + + testData1 <- testData[, c("num1", "num2")] + testData1M <- as.matrix(testData1) + + formatInfo <- write.fwf(testData1, formatInfo=TRUE) checkEquals(formatInfo, formatInfoT) + formatInfoM <- write.fwf(testData1M, formatInfo=TRUE) + checkEquals(formatInfoM, formatInfoT) + + ## scientific notation dd <- options("digits"); options(digits = 7) testData2 <- data.frame(a=123, b=pi, c=1e8, d=1e222) @@ -91,39 +99,66 @@ digits=c(0, 0, 1), exp=c(0, 0, 0), stringsAsFactors=FALSE) - formatInfoR <- write.fwf(testData[, c("num1", "num2")], formatInfo=TRUE, - rownames=TRUE, rowCol="row") + testData3 <- testData[, c("num1", "num2")] + testData3M <- as.matrix(testData3) + + formatInfoR <- write.fwf(testData3, formatInfo=TRUE, rownames=TRUE, + rowCol="row") checkEquals(formatInfoR, formatInfoTR) + formatInfoR <- write.fwf(testData3M, formatInfo=TRUE, rownames=TRUE, + rowCol="row") + checkEquals(formatInfoR, formatInfoTR) + + ## quoteInfo alone does not have any effect - formatInfoI <- write.fwf(testData[, c("num1", "num2")], formatInfo=TRUE, - quoteInfo=TRUE) + formatInfoI <- write.fwf(testData3, formatInfo=TRUE, quoteInfo=TRUE) checkEquals(formatInfoI, formatInfoT) + formatInfoI <- write.fwf(testData3M, formatInfo=TRUE, quoteInfo=TRUE) + checkEquals(formatInfoI, formatInfoT) + ## quote - formatInfoQ <- write.fwf(testData[, c("num1", "num2")], formatInfo=TRUE, - quote=TRUE) formatInfoTQ <- formatInfoT formatInfoTQ$position <- c(1, 6) formatInfoTQ$width <- c(4, 5) + + formatInfoQ <- write.fwf(testData3, formatInfo=TRUE, quote=TRUE) checkEquals(formatInfoQ, formatInfoTQ) + formatInfoQ <- write.fwf(testData3M, formatInfo=TRUE, quote=TRUE) + checkEquals(formatInfoQ, formatInfoTQ) + ## quote without quoteInfo - formatInfoQI <- write.fwf(testData[, c("num1", "num2")], formatInfo=TRUE, - quote=TRUE, quoteInfo=FALSE) formatInfoTQI <- formatInfoT formatInfoTQI$position <- c(2, 6) + + formatInfoQI <- write.fwf(testData3, formatInfo=TRUE, quote=TRUE, + quoteInfo=FALSE) checkEquals(formatInfoQI, formatInfoTQI) + formatInfoQI <- write.fwf(testData3M, formatInfo=TRUE, quote=TRUE, + quoteInfo=FALSE) + checkEquals(formatInfoQI, formatInfoTQI) + ## width ## --> default width for num1 is 2 - formatInfo <- write.fwf(testData[, "num1", drop=FALSE], width=10, formatInfo=TRUE) + testData4 <- testData[, "num1", drop=FALSE] + testData4M <- as.matrix(testData[, "num1", drop=FALSE]) + + formatInfo <- write.fwf(testData4, width=10, formatInfo=TRUE) checkEquals(formatInfo$width, 10) + formatInfo <- write.fwf(testData4M, width=10, formatInfo=TRUE) + checkEquals(formatInfo$width, 10) + ## too small value in width (this also tests recycling) ## --> proper width for num1 is 2, while for num2 it is 3 checkException(write.fwf(testData[, c("num1", "num2")], width=2)) checkException(write.fwf(testData[, c("num1", "num2")], width=c(2, 1))) + + ## Done + cat("\nDONE.\n\n") } ### }}} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |