Skip to content

Interpret bytes as another type

Source code

Description

Supported types are numerical or temporal dtypes, or an Array of these dtypes.

Usage

<Expr>$bin$reinterpret(..., dtype, endianness = c("little", "big"))

Arguments

These dots are for future extensions and must be empty.
dtype A Polars DataType or DataTypeExpr indicating which type to interpret binary column into.
endianness Which endianness to use when interpreting bytes. Must be one of “little” (default) or “big”.

Value

A polars expression

Examples

library("polars")


df <- pl$DataFrame(x = blob::as_blob(c(5L, 35L)))

df$with_columns(
  bin2int = pl$col("x")$bin$reinterpret(
    dtype = pl$UInt8,
    endianness = "little"
  )
)
#> shape: (2, 2)
#> ┌─────────┬─────────┐
#> │ x       ┆ bin2int │
#> │ ---     ┆ ---     │
#> │ binary  ┆ u8      │
#> ╞═════════╪═════════╡
#> │ b"\x05" ┆ 5       │
#> │ b"#"    ┆ 35      │
#> └─────────┴─────────┘