suppressPackageStartupMessages({ library(uint8) }) knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
uint8
- An 8-bit unsigned integer type for Rraw
type.integer
values in R are stored in 4 bytes),
so there can be memory savings.NA
, NaN
, or Inf
values allowedRcpp
).uint8_t
type in C.uint8
is stored in a single byte (but there is, of course, overhead
associated with atomic vector metainfo). uint8
can result in 25% of the memory use of R integer
values. e.g.pryr::object_size(1:10000)
=> 40 kBpryr::object_size(uint8(1:10000))
=> 10.2 kBuint8()
(data creation)+
, -
, *
, /
%%
, %/%
:
(sequence creation)any()
, all()
, as.bitstring()
, abs()
, order()
, sign()
raw
typeas.integer()
, as.numeric()
, as.character()
%in%
<
, <=
, ==
, !=
, >=
, >
uint8
for subscripts (similar limitation in the bit64
package for integer64
):
operator only dispatches on its first argument, so uint8(1):10
will work,
but 1:uint8(10)
won't.raw
raw
allows for 8-bit data, but doesn't support any arithmetic operatorsuint8
support basic arithmeticraw
accepts values outside the range 0-255 by setting them to zerouint8
accepts values outside the range 0-255 by calculating the value modulo 256.
e.g. uint8(-10)
is 246
raw
accepts NA
, NaN
, Inf
by setting them to zero. uint8
disallows NA
, NaN
and Inf
b02 <- as.uint8( 2) b0a <- as.uint8( 10) bff <- as.uint8(255) # Addition is modulo 256 bff + b0a # (255 + 10) %% 256 => 9 # Division result trucated to integer value b0a/b02 # 10/2 => 5 bff/b0a # 255/10 => 25.5 => 25 # exponentiation is modulo 256 b02 ^ b0a # 2^10 => 1024. 1024 %% 256 => 0 # initialisation is modulo 256 as.uint8(seq(200, 300, 5))
Rcpp
backend for speed or accuracy of behaviour.Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.