File: vctrs_extension_array.Rd

package info (click to toggle)
apache-arrow 23.0.1-1
  • links: PTS
  • area: main
  • in suites: sid
  • size: 76,220 kB
  • sloc: cpp: 654,608; python: 70,522; ruby: 45,964; ansic: 18,742; sh: 7,365; makefile: 669; javascript: 125; xml: 41
file content (48 lines) | stat: -rw-r--r-- 1,902 bytes parent folder | download
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
47
48
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/extension.R
\name{vctrs_extension_array}
\alias{vctrs_extension_array}
\alias{vctrs_extension_type}
\title{Extension type for generic typed vectors}
\usage{
vctrs_extension_array(x, ptype = vctrs::vec_ptype(x), storage_type = NULL)

vctrs_extension_type(x, storage_type = infer_type(vctrs::vec_data(x)))
}
\arguments{
\item{x}{A vctr (i.e., \code{\link[vctrs:vec_assert]{vctrs::vec_is()}} returns \code{TRUE}).}

\item{ptype}{A \code{\link[vctrs:vec_ptype]{vctrs::vec_ptype()}}, which is usually a zero-length
version of the object with the appropriate attributes set. This value
will be serialized using \code{\link[=serialize]{serialize()}}, so it should not refer to any
R object that can't be saved/reloaded.}

\item{storage_type}{The \link[=data-type]{data type} of the underlying storage
array.}
}
\value{
\itemize{
\item \code{vctrs_extension_array()} returns an \link{ExtensionArray} instance with a
\code{vctrs_extension_type()}.
\item \code{vctrs_extension_type()} returns an \link{ExtensionType} instance for the
extension name "arrow.r.vctrs".
}
}
\description{
Most common R vector types are converted automatically to a suitable
Arrow \link[=data-type]{data type} without the need for an extension type. For
vector types whose conversion is not suitably handled by default, you can
create a \code{\link[=vctrs_extension_array]{vctrs_extension_array()}}, which passes \code{\link[vctrs:vec_data]{vctrs::vec_data()}} to
\code{Array$create()} and calls \code{\link[vctrs:vec_proxy]{vctrs::vec_restore()}} when the \link{Array} is
converted back into an R vector.
}
\examples{
(array <- vctrs_extension_array(as.POSIXlt("2022-01-02 03:45", tz = "UTC")))
array$type
as.vector(array)

temp_feather <- tempfile()
write_feather(arrow_table(col = array), temp_feather)
read_feather(temp_feather)
unlink(temp_feather)
}