-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconvert_bytes_to_array.Rd
More file actions
46 lines (40 loc) · 1.23 KB
/
Copy pathconvert_bytes_to_array.Rd
File metadata and controls
46 lines (40 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/read_npy.R
\name{convert_bytes_to_array}
\alias{convert_bytes_to_array}
\title{Convert raw bytes to an R array based on the specified data type information}
\usage{
convert_bytes_to_array(bytes, what, shape, size, endian)
}
\arguments{
\item{bytes}{A raw vector containing the bytes to convert}
\item{what}{A character specifying the base type to convert to (e.g.,
\code{"float"}, \code{"int"}, \code{"string"}, etc.)}
\item{shape}{A numeric vector with desired shape of the output array}
\item{size}{A numeric value with the number of bytes per element for the
specified type}
\item{endian}{The endianness of the data (\code{"little"}, \code{"big"}, or \code{NA} for
single-byte types)}
}
\value{
An R array containing the converted data, with the specified shape
}
\description{
This is a replacement for \code{\link[=readBin]{readBin()}} that can handle the various data types
and endianness specified in the .npy file header.
}
\examples{
x <- matrix(c(3L, 6L, 2L, 1L, 12L, 0L), nrow = 2, ncol = 3)
x
y <- writeBin(c(x), raw()) |>
convert_bytes_to_array(
"int",
shape = c(2L, 3L),
size = 4L,
endian = "little"
)
y
dim(y)
is.array(y)
storage.mode(y)
}