This is an automated email from the ASF dual-hosted git repository.
thisisnic pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-cookbook.git
The following commit(s) were added to refs/heads/main by this push:
new b8253ad ARROW-13714: [Doc][Cookbook] Sharing data between R and
Python - R (#99)
b8253ad is described below
commit b8253ad38567ee38bf73b26637126d1e35ef3dd7
Author: Nic Crane <[email protected]>
AuthorDate: Wed Nov 3 09:55:47 2021 +0000
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
---
Makefile | 1 +
r/content/_bookdown.yml | 1 +
r/content/python.Rmd | 43 ++++++++++++++++++++++++++++++++++++++++
r/scripts/install_dependencies.R | 3 ++-
4 files changed, 47 insertions(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
index 69f0e47..95978b5 100644
--- a/Makefile
+++ b/Makefile
@@ -40,6 +40,7 @@ ifdef arrow_r_version
else
cd ./r && Rscript ./scripts/install_dependencies.R
endif
+ pip install pyarrow
r: rdeps
diff --git a/r/content/_bookdown.yml b/r/content/_bookdown.yml
index c2aab02..dd14319 100644
--- a/r/content/_bookdown.yml
+++ b/r/content/_bookdown.yml
@@ -12,5 +12,6 @@ rmd_files: [
"specify_data_types_and_schemas.Rmd",
"arrays.Rmd",
"tables.Rmd",
+ "python.Rmd",
"flight.Rmd"
]
diff --git a/r/content/python.Rmd b/r/content/python.Rmd
new file mode 100644
index 0000000..d6cf893
--- /dev/null
+++ b/r/content/python.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),]))
+ )
+})
+```
+
diff --git a/r/scripts/install_dependencies.R b/r/scripts/install_dependencies.R
index 502beea..f309081 100644
--- a/r/scripts/install_dependencies.R
+++ b/r/scripts/install_dependencies.R
@@ -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)