[adegenet-commits] r766 - in pkg: R src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Jan 18 14:04:32 CET 2011
Author: jombart
Date: 2011-01-18 14:04:32 +0100 (Tue, 18 Jan 2011)
New Revision: 766
Modified:
pkg/R/SNPbin.R
pkg/src/SNPbin.c
Log:
Conversion of raw <-> int is broken, but apparently not due to new C code.
Modified: pkg/R/SNPbin.R
===================================================================
--- pkg/R/SNPbin.R 2011-01-18 12:54:01 UTC (rev 765)
+++ pkg/R/SNPbin.R 2011-01-18 13:04:32 UTC (rev 766)
@@ -587,9 +587,14 @@
###########
## convert vector of raw to 0/1 integers
.raw2bin <- function(x){
- SNPCOMB <- as.matrix(expand.grid(rep(list(c(0,1)), 8)))
- colnames(SNPCOMB) <- NULL
- res <- unlist(lapply(as.integer(x), function(i) SNPCOMB[i+1,]))
+ if(!is.integer(x)) {
+ x <- as.integer(x)
+ }
+ ## SNPCOMB <- as.matrix(expand.grid(rep(list(c(0,1)), 8)))
+ ## colnames(SNPCOMB) <- NULL
+ ## res <- unlist(lapply(as.integer(x), function(i) SNPCOMB[i+1,]))
+ res <- .C("bytesToBinInt", x, length(x), integer(length(x)*8))[[3]]
+ return(res)
} # end .raw2bin
Modified: pkg/src/SNPbin.c
===================================================================
--- pkg/src/SNPbin.c 2011-01-18 12:54:01 UTC (rev 765)
+++ pkg/src/SNPbin.c 2011-01-18 13:04:32 UTC (rev 766)
@@ -181,7 +181,7 @@
.C("testRaw", raw(256), 256L, PACKAGE="adegenet")
## test raw->int conversion
-x <- sample(0:1,80,replace=TRUE)
+x <- sample(0:1,800,replace=TRUE)
toto <- .bin2raw(x)$snp
all(.C("bytesToBinInt", toto, length(toto), integer(length(toto)*8))[[3]]==x)
More information about the adegenet-commits
mailing list