as.ff.bit.rdFunction as.ff.bit converts a bit vector to a boolean ff vector.
Function as.bit.ff converts a boolean ff vector to a ff vector.
# S3 method for class 'bit'
as.ff(x, filename = NULL, overwrite = FALSE, ...)
# S3 method for class 'ff'
as.bit(x, ...)The data are copied bot bit-wise but integerwise, therefore these conversions are very fast.
as.bit.ff will attach the ff filename to the bit vector, and as.ff.bit will - if attached - use THIS filename and SILENTLY overwrite this file.
NAs are mapped to TRUE in 'bit' and to FALSE in 'ff' booleans. Might be aligned in a future release. Don't use bit if you have NAs - or map NAs explicitely.
A vector of the converted type
l <- as.boolean(sample(c(FALSE,TRUE), 1000, TRUE))
b <- as.bit(l)
stopifnot(identical(l,b[]))
b
#> bit length=1000 occupying only 32 int32
#> 1 2 3 4 5 6 7 8 993 994 995 996
#> FALSE FALSE FALSE TRUE TRUE TRUE TRUE TRUE .. FALSE FALSE TRUE FALSE
#> 997 998 999 1000
#> FALSE TRUE TRUE TRUE
f <- as.ff(b)
stopifnot(identical(l,f[]))
f
#> ff (open) boolean length=1000 (1024)
#> [1] [2] [3] [4] [5] [6] [7] [8] [993] [994]
#> FALSE FALSE FALSE TRUE TRUE TRUE TRUE TRUE : FALSE FALSE
#> [995] [996] [997] [998] [999] [1000]
#> TRUE FALSE FALSE TRUE TRUE TRUE
b2 <- as.bit(f)
stopifnot(identical(l,b2[]))
b2
#> bit length=1000 occupying only 32 int32
#> 1 2 3 4 5 6 7 8 993 994 995 996
#> FALSE FALSE FALSE TRUE TRUE TRUE TRUE TRUE .. FALSE FALSE TRUE FALSE
#> 997 998 999 1000
#> FALSE TRUE TRUE TRUE
f2 <- as.ff(b2)
stopifnot(identical(filename(f),filename(f2)))
stopifnot(identical(l,f2[]))
f
#> ff (open) boolean length=1000 (1024)
#> [1] [2] [3] [4] [5] [6] [7] [8] [993] [994]
#> FALSE FALSE FALSE TRUE TRUE TRUE TRUE TRUE : FALSE FALSE
#> [995] [996] [997] [998] [999] [1000]
#> TRUE FALSE FALSE TRUE TRUE TRUE
rm(f,f2); gc()
#> used (Mb) gc trigger (Mb) max used (Mb)
#> Ncells 1020252 54.5 1994352 106.6 1994352 106.6
#> Vcells 1880016 14.4 8388608 64.0 3877600 29.6