R Under development (unstable) (2023-12-07 r85661 ucrt) -- "Unsuffered Consequences" Copyright (C) 2023 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 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. 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. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(mmap) > tmp <- tempfile() > > ##### int8() ##### > # write binary from min to max signed 2^8 > test.int8 <- function() { + writeBin(-128:127L, tmp, size=1) + + m <- mmap(tmp, int8()) # signed 1 byte integers + if( !all(m[] == (-128:127L)) ) + stop("m[] == (-128:127L)") + + # test replacement + m[] <- -128L + if( !all(m[] == -128)) + stop("m[] == -128") + munmap(m) + } > > > > > #### uint8() #### > test.uint8 <- function(on=TRUE) { + if( !isTRUE(on)) { + cat("test.uint8 disabled\n") + return(NULL) + } + writeBin(0:255L, tmp, size=1) + m <- mmap(tmp, uint8()) # unsigned 1 byte integers + if( !all(m[] == 0:255L) ) + stop("m[] == 0:255L") + + # test replacement + m[] <- 255L; + if( !all(m[] == 255L)) + stop("m[] == 255L") + munmap(m) + } > > > > > #### int16() #### > test.int16 <- function(on=TRUE) { + if( !isTRUE(on)) { + cat("test.int16 disabled\n") + return(NULL) + } + writeBin(-32768:32767L, tmp, size=2) + m <- mmap(tmp, int16()) # signed 2 byte integers + if( !all(m[] == -32768:32767L) ) + stop("m[] == -32768:32767L") + + # test replacement + m[] <- -32768L + if( !all(m[] == -32768L)) + stop("m[] == -32768L") + munmap(m) + } > > > > > #### uint16() #### > test.uint16 <- function(on=TRUE) { + cat("checking test.uint16...") + if( !isTRUE(on)) { + cat("test.uint16 disabled\n") + return(NULL) + } + writeBin(0:65535L, tmp, size=2) + m <- mmap(tmp, uint16()) # unsigned 2 byte integers + if( !all(m[] == 0:65535L) ) + stop("m[] == 0:65535L") + + # test replacement + m[] <- 65535L + if( !all(m[] == 65535L)) + stop("m[] == 65535L") + munmap(m) + cat("OK\n") + } > > > > > #### int24() #### > test.int24 <- function(on=TRUE) { + cat("checking test.int24...") + if( !isTRUE(on)) { + cat("test.int24 disabled\n") + return(NULL) + } + ints <- as.integer(seq(-8388607L,8388607L,length.out=11)) + writeBin(rep(as.raw(0),33), tmp) + m <- mmap(tmp, int24()) # signed 3 byte integers + m[] <- ints + if( !all(m[] == ints) ) + stop("m[] == ints") + munmap(m) + cat("OK\n") + } > > > > > #### uint24() #### > test.uint24 <- function(on=TRUE) { + cat("checking test.uint24...") + if( !isTRUE(on)) { + cat("test.uint24 disabled\n") + return(NULL) + } + ints <- as.integer(seq(0,16777215L,length.out=100)) + writeBin(rep(as.raw(0),300), tmp) + m <- mmap(tmp, uint24()) # signed 3 byte integers + m[] <- ints + if( !all(m[] == ints) ) + stop("m[] == ints") + munmap(m) + cat("OK\n") + } > > > > > #### int32() #### > test.int32 <- function(on=TRUE) { + cat("checking test.int32...") + if( !isTRUE(on)) { + cat("test.int32 disabled\n") + return(NULL) + } + writeBin(-1e6:1e6L, tmp, size=4) + m <- mmap(tmp, int32()) # unsigned 2 byte integers + if( !all(m[] == -1e6:1e6L) ) + stop("m[] == -1e6:1e6L") + + # test replacement + m[] <- .Machine$integer.max + if( !all(m[] == .Machine$integer.max)) + stop("m[] == .Machine$integer.max") + munmap(m) + cat("OK\n") + } > > > > > #### int64() #### > test.int64 <- function(on=TRUE) { + cat("checking test.int64...") + if( !isTRUE(on)) { + cat("test.int32 disabled\n") + return(NULL) + } + writeBin(0.0, tmp) + m <- mmap(tmp, int64()) # signed 8 byte integers as doubles + m[] <- 2^40 + if( !all(m[] == 2^40) ) + stop("m[] == 2^40") + munmap(m) + cat("OK\n") + } > > test.int8() > test.uint8() > test.int16() > test.uint16() checking test.uint16...OK > test.int24() checking test.int24...OK > test.uint24() checking test.uint24...OK > test.int32() checking test.int32...OK > test.int64(FALSE) checking test.int64...test.int32 disabled NULL > > proc.time() user system elapsed 0.25 0.06 0.29