4 Creating Arrow Objects

4.1 Create an Arrow Array from an R object

You want to convert an existing vector in R to an Arrow Array object.

4.1.1 Solution

# Create an example vector
score = c(99, 97, 99)

# Convert to Arrow Array
score_array <- Array$create(score)

# View Array
score_array
## Array
## <double>
## [
##   99,
##   97,
##   99
## ]

4.2 Create a Arrow Table from an R object

You want to convert an existing data frame in R to an Arrow Table object.

4.2.1 Solution

# Create an example data frame
my_tibble <- tibble::tibble(group = c("A", "B", "C"), score = c(99, 97, 99))
# Convert to Arrow Table
my_table <- arrow_table(my_tibble)
# View table
my_table
## Table
## 3 rows x 2 columns
## $group <string>
## $score <double>

4.3 View the contents of an Arrow Table or RecordBatch

You want to view the contents of an Arrow Table or RecordBatch.

4.3.1 Solution

# View Table
dplyr::collect(my_table)
## # A tibble: 3 × 2
##   group score
##   <chr> <dbl>
## 1 A        99
## 2 B        97
## 3 C        99

4.4 Manually create a RecordBatch from an R object.

You want to convert an existing data frame in R to an Arrow RecordBatch object.

4.4.1 Solution

# Create an example data frame
my_tibble <- tibble::tibble(group = c("A", "B", "C"), score = c(99, 97, 99))
# Convert to Arrow RecordBatch
my_record_batch <- record_batch(my_tibble)
# View RecordBatch
my_record_batch
## RecordBatch
## 3 rows x 2 columns
## $group <string>
## $score <double>