File: match_arrow.Rd

package info (click to toggle)
apache-arrow 23.0.1-4
  • links: PTS
  • area: main
  • in suites:
  • size: 76,368 kB
  • sloc: cpp: 654,608; python: 70,522; ruby: 45,964; ansic: 18,742; sh: 7,367; makefile: 633; javascript: 125; xml: 41
file content (51 lines) | stat: -rw-r--r-- 1,873 bytes parent folder | download | duplicates (6)
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
49
50
51
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/compute.R
\name{match_arrow}
\alias{match_arrow}
\alias{is_in}
\title{Value matching for Arrow objects}
\usage{
match_arrow(x, table, ...)

is_in(x, table, ...)
}
\arguments{
\item{x}{\code{Scalar}, \code{Array} or \code{ChunkedArray}}

\item{table}{\code{Scalar}, Array\verb{, }ChunkedArray`, or R vector lookup table.}

\item{...}{additional arguments, ignored}
}
\value{
\code{match_arrow()} returns an \code{int32}-type Arrow object of the same length
and type as \code{x} with the (0-based) indexes into \code{table}. \code{is_in()} returns a
\code{boolean}-type Arrow object of the same length and type as \code{x} with values indicating
per element of \code{x} it it is present in \code{table}.
}
\description{
\code{base::match()} and \verb{base::\%in\%} are not generics, so we can't just define Arrow methods for
them. These functions expose the analogous functions in the Arrow C++ library.
}
\examples{
# note that the returned value is 0-indexed
cars_tbl <- arrow_table(name = rownames(mtcars), mtcars)
match_arrow(Scalar$create("Mazda RX4 Wag"), cars_tbl$name)

is_in(Array$create("Mazda RX4 Wag"), cars_tbl$name)

# Although there are multiple matches, you are returned the index of the first
# match, as with the base R equivalent
match(4, mtcars$cyl) # 1-indexed
match_arrow(Scalar$create(4), cars_tbl$cyl) # 0-indexed

# If `x` contains multiple values, you are returned the indices of the first
# match for each value.
match(c(4, 6, 8), mtcars$cyl)
match_arrow(Array$create(c(4, 6, 8)), cars_tbl$cyl)

# Return type matches type of `x`
is_in(c(4, 6, 8), mtcars$cyl) # returns vector
is_in(Scalar$create(4), mtcars$cyl) # returns Scalar
is_in(Array$create(c(4, 6, 8)), cars_tbl$cyl) # returns Array
is_in(ChunkedArray$create(c(4, 6), 8), cars_tbl$cyl) # returns ChunkedArray
}