# Using PyArrow from R

## Introduction

For more information on using setting up and installing PyArrow to use in R, see 
[the "Apache Arrow in Python and R with reticulate" vignette](https://arrow.apache.org/docs/r/articles/python.html). 

## Create an Arrow object using PyArrow in R

You want to use PyArrow to create an Arrow object in an R session.

### Solution

```{r, pyarrow_object}
library(reticulate)
pa <- import("pyarrow")
pyarrow_scalar <- pa$scalar(42)
pyarrow_scalar
```
```{r, test_pyarrow_object, opts.label = "test"}
test_that("pyarrow_object", {
  expect_s3_class(pyarrow_scalar, "pyarrow.lib.Scalar")
})
```

## Call a PyArrow function from R

You want to call a PyArrow function from your R session.

### Solution

```{r, pyarrow_func}
table_1 <- Table$create(mtcars[1:5,])
table_2 <- Table$create(mtcars[11:15,])

pa$concat_tables(tables = list(table_1, table_2)) %>%
  collect()
```
```{r, test_pyarrow_func, opts.label="test"}
test_that("pyarrow_func", {
  expect_equal(
    collect(pa$concat_tables(tables = list(table_1, table_2))),
    collect(Table$create(mtcars[c(1:5,11:15),]))
  )
})
```

