as.big.matrix() with type "raw"
I tried:
> x <- matrix(as.raw(sample(0:255, 100)), 10, 10)
> class(x)
[1] "matrix"
> typeof(x)
[1] "raw"
> as.big.matrix(x, type = "raw")
Error in SetMatrixElements(x@address, as.double(j), as.double(i), value) :
RAW() can only be applied to a 'raw', not a 'double'
In addition: Warning messages:
1: In as.big.matrix(x, type = "raw") : Casting to numeric type
2: In SetElements.bm(x, i, j, value) :
Assignment will down cast from double to raw
Hint: To remove this warning type: options(bigmemory.typecast.warning=FALSE)
Am I doing something wrong or is it a missing implementation?
@adamryczkowski
No, it is a bug. What works (and what I have been doing) is:
x <- matrix(as.raw(sample(0:255, 100)), 10, 10)
m<-big.matrix(10,10,type='raw')
m[,]<-x
I'll look at it.
Now your code work as expected.
Thank you for testing my patch :-)
Hence the perpetual need for more unit tests :)
So here it is :-)
Thanks for https://github.com/kaneplusplus/bigmemory/pull/48
Thanks @adamryczkowski. I've merged the pull request.
@adamryczkowski I'll continue here, because this is about "raw" big.matrices. This is only a minor bug, but subsetting with a matrix is returning numeric elements, not raw ones.
Example:
x <- matrix(as.raw(sample(0:255, 100)), 10, 10)
X <- as.big.matrix(x, type = "raw") # so this now works :-)
ind <- cbind(1, 2:3)
ind
X[ind]
X[1, 2:3]