Skip to content
Permalink
Browse files
ARROW-13714: [Doc][Cookbook] Sharing data between R and Python - R (#99)
* Initial file

* Add to bookdown file

* Add examples

* Add example of PyArrow functions

* Initial file

* Add to bookdown

* Add examples

* Add example of PyArrow functions

* Capitalisation

* Update dependencies

* Add pyarrow installation

* Consistent capitalisation
  • Loading branch information
thisisnic committed Nov 3, 2021
1 parent edf8308 commit b8253ad38567ee38bf73b26637126d1e35ef3dd7
Showing 4 changed files with 47 additions and 1 deletion.
@@ -40,6 +40,7 @@ ifdef arrow_r_version
else
cd ./r && Rscript ./scripts/install_dependencies.R
endif
pip install pyarrow


r: rdeps
@@ -12,5 +12,6 @@ rmd_files: [
"specify_data_types_and_schemas.Rmd",
"arrays.Rmd",
"tables.Rmd",
"python.Rmd",
"flight.Rmd"
]
@@ -0,0 +1,43 @@
# 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.

```{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.

```{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),]))
)
})
```

@@ -81,7 +81,8 @@ install_arrow_version <- function(version_to_install) {
}
}

dependencies <- c("testthat", "bookdown", "knitr", "purrr", "remotes", "dplyr")
dependencies <- c("testthat", "bookdown", "knitr", "purrr", "remotes",
"dplyr", "stringr", "reticulate")

for (dependency in dependencies) {
load_package(dependency)

0 comments on commit b8253ad

Please sign in to comment.