## ----setup--------------------------------------------------------------------
library(grumpy)


## -----------------------------------------------------------------------------
read_npy(system.file("extdata", "test_2d.npy", package = "grumpy"))


## -----------------------------------------------------------------------------
read_npz(system.file("extdata", "test.npz", package = "grumpy"))

# we can read only some of the arrays in the archive
read_npz(
  system.file("extdata", "test.npz", package = "grumpy"),
  arrays = "x"
)
# or equivalently
read_npz(
  system.file("extdata", "test.npz", package = "grumpy"),
  arrays = 1L
)


## -----------------------------------------------------------------------------
struct <- read_npy(
  system.file("extdata", "test_structured.npy", package = "grumpy")
)
struct
dim(struct)
struct[[1L]]


## -----------------------------------------------------------------------------
unlist(struct) |>
  matrix(ncol = length(struct[[1L]]), byrow = TRUE) |>
  as.data.frame()

